3D Player keeps facing one way after moving and facing different directions

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

Hi. I’m currently new to Godot and game development and programming in general. I currently have a working 3D third-person player controller working nicely. It moves and the model correctly faces the direction it is moving towards. My problem is that after I let go of any of WASD, it reverts back and faces front again. Facing in the intended direction while moving works great. It’s just that it would not stay idle and face the direction it was facing at and instead reverts back to facing to its initial pose. I am currently a beginner at game development and I would be grateful for your help if you have the time to spare. Thank you. Here are my scenes and the code I am currently using. please do tell if there is anything else I may give to help solve the problem.

Scenes and Code:

Video showing problem:

:bust_in_silhouette: Reply From: DiMiMi

Line 48 is the issue:

$Mesh.rotation.y = lerp_angle($Mesh.rotation.y, atan2(move_vec.x, move_vec.z), delta * ang_accel)

When you don’t press a button, move_vec will always be Vector3(0,0,0).
Because of that, atan2(move_vec.x, move_vec.z) will always return 0. So the character will rotate to it’s 0 rotation, when you don’t press anything. You can solve this problem by putting, for example If move_vec.z != 0 or move_vec.x != 0: before Line 48.

Hi thank you so much for responding! I tried the example you gave and it stopped making the move_vec to be Vec3(0,0,0), although another problem came up which is the model suddenly faces on all diagonals and doesn’t seem to correspond to the direction it’s supposed to be facing. I tried making it into lerp instead on lerp_angle but it still appears to be the problem.


MD25 | 2020-10-08 15:16

Would you mind sharing your project that i can try some things out?

DiMiMi | 2020-10-08 15:35

Of course! Here’s the G Drive to the Proj Folder

MD25 | 2020-10-08 15:42

I will look into tomorrow and will report back.

DiMiMi | 2020-10-08 15:55

Thank you again very much for lending me your time!

MD25 | 2020-10-08 15:56

Found the solution:
Your code has and instead of or in the If move_vec.z != 0 or move_vec.x != 0 line. It may be my fault, because i wrote it wrong first and then edited my answer 2 minutes after that. I think you just saw the wrong version instead of the new one.

This is not question related but since you wrote you are new to Godot and programming, i want to give you some advice:

  1. Your Solid Snake is a tall guy. That is fine is you want that, but i would recommend sticking to the Godot Unit system. 1 Unit = 1 Meter. Keeping your propotions from beginning makes life easier in the long term. The physics in Godot are also based on that scale and it’s easier to keep proportions in the leveldesign later on.

  2. Currently you call $Meshin every _physics_process step. This is ok when you are just testing and/or your game is not that big. It’s not so good when do it with a lot of objects (slow!) and/or creates a problem when you change your tree order. It’s better when you do var mesh outside of the functions and then domesh = $mesh in _ready(). Then keep using mesh instead of $mesh.

Hope this helps. Good luck! :slight_smile:

DiMiMi | 2020-10-09 07:46

Oh thank you so much! Thank you also for your helpful advice! I hope you have a good day and continue with what project you’re currently working on! Thank you again for your help!

MD25 | 2020-10-09 07:52

thanks this helped me out.

morningkingdom | 2022-03-19 18:05