TLDR: How do I prevent the camera from jumping when the character jumps?
Hi there,
I am creating a different camera system since the default third person camera doesnt fit what I’m working on.
Currently, I am trying to prevent the camera from jumping with the character whenever the character jumps. This is default behaviour of the third person camera.
What I did:
I created 2 scene components inside my Character blueprint.
- CameraLookTarget
- CameraAnchor
CameraTarget is set on a fixed height above the last touched floor by the character.
CameraAnchor follows CameraTarget.
The CameraBoom/SpringArm is attached to CameraAnchor.
CameraLookTarget keeps following the characters X and Y value but is on a fixed Z value above the floor until the character touches a different floor/platform at a different height. If that happens, the Z value is calculated so that CameraLookTarget is again at a certain height above the “new current floor”.
This is done so that the camera only jumps with the character if it really has to for example when the character lands on a higher or lower platform.
Code below:
Rest of the function:
And after this function has been called, I set the CameraBoom/SpringArm to this:
This works almost fine but there is one small issue.
The Problem:
When the character jumps, CameraLookTarget goes just a little bit up and moves down when the character falls. Once the character lands, CameraLookTarget jumps back to the actual Z Height which I’ve set before.
The Z Height never changes during the entire process until the character lands on a different floor so I cannot understand why there is a small change in the height of CameraLookTarget when jumping.
This behaviour causes a “snapping” of CameraLookTarget and hence CameraAnchor which results in the camera snapping every time when the character lands on the same floor.
Video below:
The purple sphere is CameraLookTarget. As you can see the height stays the same when the character moves around however when the character jumps, the height goes a bit up and down which results of the camera snapping on landing.
What I have tried so far:
I found out that if I remove the Interp To node for the camera boom, the snapping effect goes away but the slight movement of CameraLookTarget stays. But I need the Interp node to move the camera smoothly from floor to floor.
I also tried printing out the Z values of the CameraLookTargetHeight and its always stays the same. My guess is that in the first Code Block I’ve attached above, in the false-block when I set the CameraLookTarget, something weird happens when setting the world location with “Set World Location”. Maybe rounding errors?
Appreciate any kind of help and ideas
Thanks!