Rotate character based on direction?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HaptikRevamp

How can you make the character rotate based on the direction of the movement?
for example when the character is running forward and is now running back the character “not the camera” will rotate facing the camera.

Can you elaborate , is this a first person camera or third??

Mrpaolosarino | 2021-05-08 03:50

:bust_in_silhouette: Reply From: magicalogic

Then don’t make the camera a child of the player, make it a child of the level and code it to follow the player . To rotate the character in the direction of the movement, set their velocity (assuming you have this variable) as velocity=velocity.rotated(rotation).This will work if you are rotating the character yourself when certain keys are pressed.

To make the camera follow the player all you have to play with is the translation variable. Just get the distance between the character and the camera at the start of the game and be adding it to the translation of the camera in _process(delta).

You can also reset the cameras rotation to zero in _process() while its still a child of the player.

magicalogic | 2021-05-08 05:18

:bust_in_silhouette: Reply From: scrubswithnosleeves

Answering your Question LIVE on YouTube: