I’m trying to implement a lock-on camera system. I got it working for the most part, but now I’m trying to move the camera such that the player and target both occupy the screen horizontally (ala For Honor). I do this by first offsetting the camera by a constant, then having the camera LookAt the midpoint between the player and target.
The problem arises when the distance between player and target are close enough that the static offset of the camera forces it to continuously rotate itself to try and focus on the midpoint. But because the offset length is constant, the camera will never reach b so it just keeps spinning.
I’ve made some illustrations:
A is the player. B is the target/midpoint. C is the Camera. cb is the camera boom (Spring Arm), and cbo is the offset from the Spring Arm.
As this diagram shows, when b is too short, c will constantly attempt to rotate via camera boom to lock back on, but the offset means it will never reach b.
I thought up two ways to solve this, but I cannot figure out how to do either:
Rotate the camera. I’ve tried to apply SetWorldRotation of the camera component to the LookAt vector, but that doesn’t seem to work… The camera doesn’t even rotate.
Shorten the distance of cb -> cbo so that c -> b will meet again. Unfortunately my math is poor, and I can’t figure out any solutions that do not involve rotation of C’s angle (which really just brings me back to solution 1)
Does anyone have any ideas on how to achieve either solution?
Well you need to determine the offset based on the targets forward vector and length
Like drawing a line trace to get the end location. Cept if your trying to get to point of intercept to be looking at with no gravity you’d want to… Hmmmm
Get target…
Target - Get world location and get velocity
So take these and do this with it:
Target location vector - player location vector take that get its length…
That length divide by speed of projectile that would intercept it… Now multiple target velocity by that value. Take that return and add the players location vector. This will return the projected destination of intercept.
You can test this by using that return to an end for line trace and make players location the start
Thanks for replying! I’m don’t entirely understand your solution - you mention speed of a projectile although in my case there are no projectiles involved here.
I ended up using a crude solution of measuring |A -> B| and comparing to |A -> C|. If the |A -> B| < |A -> C|, then reduce camera offset by half. It works and stops the spinning, and I’ll fine-tune it to allow variable offsets.