|
|
|
|
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.
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?
DiMiMi | 2020-10-08 15:35
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!
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:
-
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.
-
Currently you call $Mesh
in 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!
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!
thanks this helped me out.
morningkingdom | 2022-03-19 18:05