Godot Version
4.3
Question
Why is my variable changing?
I have a top-down game with a fixed camera rotation where the player character is controlled with the keyboard, and I want them to point their model the direction that they’re walking. However, I want smooth transitions from direction to direction, so I’ve come up with a system to create a looking target and point the player at that target.
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
if pointing == 0 and direction:
var looktarget = position+Vector3(direction.x, 0, direction.z)
var currenty = bodyrotator.transform.basis.get_euler().y
var targety = bodyrotator.transform.looking_at(looktarget).basis.get_euler().y
if currenty != targety:
print(targety)
move_and_slide()
My issue is that “targety” isn’t actually the number that it needs to be right off the bat. Rather, it slowly drifts towards that number as the player holds down the key (i.e. as the player holds down the S key, the value of targety will slowly approach zero over the course of five or six seconds - or longer). I’m not sure what’s going on but it means I cannot use this method to point the player, as they will be pointing in the wrong direction for too long.