Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to constantly move one actor smoothly

Hi. So this is the scenario:

I have two actors(player characters) that are constantly moving in random diretions and a camera that simply finds the center of both players and set itself in that location

alt text

but sometimes the players teleport to other locations and that changes instantatly the center of both characters wich means the camera too, and that just looks bad.

How can i make the camera follow the center of both characters smoothly.

Product Version: UE 4.20
1.png (65.0 kB)
more ▼

asked Dec 12 '18 at 02:20 AM in Blueprint Scripting

avatar image

43 6 4 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You can use Camera Boom (Spring Arm Component) to have nice smooth camera location transitions.

In the component enable the camera lag and set it to desired value (lower == slower):


When having the camera on your character (you can see the UE example TopDown or ThirdPerson templates to see how it's added there) you can use it like that, e.g. in EventTick or in some timer:


Then the camera will follow the middle point smoothly, even in case of player teleport. I've tested it, here is how it looks like, with sudden player teleport included:


(Smoother version)

You can also use the SpringArmComponent Target Arm Length to add some zoom in/out depending on your Player1 <---> Player2 distance.

ah12.png (7.8 kB)
ah13.png (131.7 kB)
more ▼

answered Dec 12 '18 at 03:56 PM

avatar image

2k 157 153 209

avatar image Colatran Dec 12 '18 at 11:29 PM

lag shure did the camera move smoothly but this still hapens

alt text

i've also tried to lower the sepeed but nothing.

ps: it's a 2d game with no prespective so the zoom has to be the camera's ortho width.

2.gif (1.0 MB)
avatar image Slavq Dec 12 '18 at 11:41 PM

What happens exactly? Both pawns are teleported in that gif? I've just tested it on my end and when both pawns are teleported (SetActorLocation), then the camera goes smoothly to their new location, so I'm not sure what happens with your pawns.

avatar image Colatran Dec 12 '18 at 11:58 PM

basicaly the red sphere is the moving pawn atacking the other. and when the other dies he spawns in the center of the map, in front of the yellow square. sorry for this gif.

avatar image Slavq Dec 13 '18 at 10:09 AM

If it dies and spawns back, then maybe the OtherPawn reference is invalid for that time. Can be checked by IsValid node.

Also, if the SpringArmComponent is attached to the pawn that dies, then it will reset like that, since it destroys the actor and spawns it back.

So if your player is destroyed and spawned back, then probably a separate actor will be needed for camera. So the camera with SpringArm is not inside your player blueprint and it won't be destroyed as well. Worth trying.

avatar image Colatran Dec 13 '18 at 07:18 PM

The player pawn is never destroyed it just changes a few variables (ex:animation) and teleports to the center of the map (setActorLocation). And the camera is already a seperated actor.

avatar image Slavq Dec 13 '18 at 08:27 PM

Well, I don't know how your blueprint logic is built there, but something must interfere with the camera or Spring Arm Component. As you can see on my gif, it works properly when being used on other actors. To narrow down the issue you can e.g. test it on other actor - e.g. tell the camera actor to follow some other actors (not your pawn class), and also make these actors snap to the map center. If that will work ok, then you'll know that there is something wrong inside your pawn class.

avatar image aNorthStar Dec 14 '18 at 02:17 PM

Colatran, I know you mentioned that your camera is a separate actor... but in your GIF... from the way it moves, it really looks like it is a component of one character, or its position is closely linked to ONE character

avatar image Colatran Dec 14 '18 at 07:52 PM

the camera gets all ators of class of the player character and saves them in an array. sorry for the bad gif

avatar image Colatran Dec 14 '18 at 07:50 PM

i've tryed with other actor still the same:

alt text

can you send me the blueprint of your camera?

3.gif (4.1 MB)
avatar image Slavq Dec 14 '18 at 07:58 PM

It's the screenshot here, nothing more. It's placed inside the UE Third Person template character in EventTick, using the already placed CameraBoom there. The OtherPawn is saved once, by GetAllACtorsOfClass() and picking the first one from the array, on BeginPlay. Maybe you can test it on your own, on the same setup (Third Person Character template) so you can see why this works and your setup don't.

avatar image Colatran Dec 18 '18 at 11:13 AM

I found the issue, there's nothing wrong with the blueprints, just had to disable "do collision test":

alt text

Thank you so much!!

fix.png (4.6 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question