0 votes

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:
https://imgur.com/a/IucxiIU

Video showing problem:
https://drive.google.com/file/d/1DNcwm30D1Z2Tf52fxF25RE2gF6POhj-z/view?usp=sharing

in Engine by (15 points)

1 Answer

+1 vote
Best answer

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.

by (122 points)
selected by

Hi thank you so much for responding! I tried the example you gave and it stopped making the movevec 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 lerpangle but it still appears to be the problem.

Issue:
https://drive.google.com/file/d/1QH0mQMGvgZ_GhIVQaYAjXBbeBzfhG_4O/view?usp=sharing

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

I will look into tomorrow and will report back.

Thank you again very much for lending me your time!

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! :)

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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.