Why does Camera class (3D) lag?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By raould
:warning: Old Version Published before Godot 3 was released.

I am using something like the script below, but the camera lags/drags/interpolates/does something that makes it not actually be in lock-step with the target node instance.

The camera’s parent is the root node, for several reasons. It is a sibling of the plaeyr node. When I try to put the camera as a child of the player, then the lag goes away. (But overall that approach isn’t a good thing for the way I am trying to do things.)

I cannot fathom why the Camera would lag when I am using set_translation(). I did also do some prints() stuff and saw that the GDScript was settting the camera translation with no lag from the player. The y coordinates matched as I expected.

So I am utterly confused as to how the camera is apparently not immediately going to the position I set on it.

func _process( delta ):
    var t = get_translation()
    var pt = player.get_translation()
    set_translation( Vector3( pt.x, pt.y, t.z ) )

Try to do it in _fixed_process()? By “lag”, do you actually mean that the camera is one frame behind? Or is it really off by a lot?
Also, make sure you move your character before moving the camera.

Zylann | 2016-08-20 12:06

Thank you for the suggestion. I tried it – it made my camera script stop working; the camera never moves any more. I move the ‘character’ using _process(delta), and so far it seems like I have to use _process(delta) for the camera as well, I guess.

And I sometimes turned off my camera moving code to try to debug this issue, and can see that my ‘character’ properly stops at the boundaries, so I think it is a camera thing, not a ‘character’ thing.

The ‘character’ is a mesh node. I did put in prints() stuff to see the order and it did move before the camera; the camera matched the ‘character’ rather than having lagging numbers.

It really feels to me like the camera implementation is doing something that interpolates, even though it is explicitly not an InterpolatingCamera instance, just a reagular Camera.

Currently the ‘character’ and camera are siblings. When I make the camera a child of the ‘character’ then the “lag” goes away. However doing it that way complicates other things I want to do. I don’t always want the camera to be tied to the ‘character’.

raould | 2016-08-23 04:20

:bust_in_silhouette: Reply From: Zylann

I tested myself and this project shows a camera that doesn’t lags:
http://zylannprods.fr/dl/godot/CameraFollow3D.zip

I also found that if the camera is located before its target in the hierarchy, it will have 1 frame of lag. If it is located after, it has no lag.

If I set the position of the camera inside the _process() of the moving object, there is no lag, even if you change the camera’s location in the hierarchy.

oh my goodness, that ordering trick worked!

raould | 2016-08-24 05:00