New camera system | Prevent camera from jumping with character

Figured out an even better way to do it, without using world location.

Functionally it ‘plays’ exactly like the gif in my last post.

24-07-23


But it’s better, because it’s fully dynamic, it assumes you are only changing the location of your camera relative to your character in the blueprint on the Z axis (but if that’s not the case for the relative transform then changing this code to use the whole relative location vector instead of getting only the Z)

The benefits to doing it this way are:

  • Any changes made to the camera boom in the blueprint’s settings are automatically respected (you don’t need to change the code if you decide you wanna move the camera a lil higher or lower relative to the character)
  • Since it uses relative transform there are fewer opportunities for game breaking bugs, especially because when the character lands the relative location is set to it’s original default setting, so whenever your character lands your camera is guaranteed to be set exactly like it’s supposed to be with no way for it to go wrong.

If you would like to add interpolation after the do-once node, I would suggest using a timeline. You want as little code as possible to run on every tick as a general rule, it’s always the first thing to optimize for any game.

Another problem you’re likely to encounter is if you run off a ledge instead of jumping, the height wont’ be saved properly because it assumes that you only need it saved when you jump, to solve that the simplest solution would just be to set gnd height whenever any movement key is pressed and the character is not falling, just to be sure.

1 Like