Absolute Basic: How to proper rotate the top-down-player? – Programming


In my top-down game (Zelda style) I want to be able to use the arrow keys to move the player left, right, up and down.

The PlayerController script inherits from CharacterBody3D, which is why I can easily calculate the velocity with the input vector.

velocity.X = direction.X * Speed;
velocity.Z = direction.Z * Speed;

And of course this works too.
However, this no longer works as soon as I rotate the player scene slightly in the editor.
Then of course the X and Z coordinates are no longer the same as the global ones (i.e. those on the monitor).

This also leads me to the question of how I rotate the player optically. It would be possible to always rotate the child node mesh and never the player node (root) itself. But somehow that sounds wrong to me…

How could I implement this?



Source link

Leave a Comment