I’m putting this in C++ because it’s a C++ project but I don’t mind if the solution is done in blueprint.
My players are free-floating cameras, moving around with WASD. Imagine a typical RTS style but the cameras can also rotate their yaw.
I want to find a way to have them “focus” on an actor in the world. By this, I mean they will move towards the actor until they are N units away and rotate to face them. I think I can manage this part. What I’m having trouble with is that my actors can move around and I want the players to move with them.
At first I tried utilizing Set View Target with Blend. I added a spring arm and camera to my actor and used the actor as the new view target. This ALMOST behaved like I wanted. (See video)
. The problem is that the spring arm on the actor will either rotate around as the actor rotates or not rotate at all. But in order to have the desired effect, I need it to always be rotated towards the player so when they “focus” the actor the camera doesn’t need to circle around to get to the camera. So I don’t think Set View Target will be what I want. (especially because this is multiplayer and I can’t have the spring arms from all actors continually rotating to be the same “look at” rotation to all players simultaneously).
I tried Attach Actor to Actor which works … as long as the actor doesn’t rotate. When the actor rotates the player swings around to keep rotation relative to the actor.
The only other thing I can think of to do is to, on a repeating timer, tell the player camera to lerp towards the actor. I feel like this will look very jarring/stuttering though.
Is there any other solution I might implement?
Also I understand I may have phrased this poorly so if further clarification is needed please ask.
You can “GetWorldLocation” of your camera as the start and “GetActorLocation” of the actor you want to follow as your target of a “FindLookAtRotation” node and the return value you can connect to New Rotation of a “SetWorldRotation” (target is scene component) node where the target is your camera. When that camera is set to active it will follow the actor on the camera’s stationary axis for sure, but I’m sure you can get it to move and follow if perhaps its a child of a moving actor, but I haven’t tried that yet…
You have to set use pawn control rotation to false of your camera or it won’t follow or move. This also has to update on tick or bind a timer to an event and loop at an interval low enough that it keeps updating smoothly… I don’t know if that’s exactly what you are wanting or helps, but it will get your camera following in blueprints.
If you know the syntax you could probably write that pretty quickly in C++.