Godot Version
4.6
Question
Hello,
I am programming a platformer game with really fancy movement. I recently ran into an issue where I try to change the player’s velocity with another script, and it gets overridden by a velocity change within the player’s code.
This made me wonder if I am changing the player’s velocity the right way. Should I do it all in the middle of processing, or should I instead queue all velocity changes and then apply them at the end of the process call?
What’s “player velocity”?
The “player velocity” is the forward and vertical velocity of the player character.
if you do any CharacterBody2D velocity changes from the result of a collision you may need to defer such a change to the end of the frame.
If you use move_and_slide velocity is copied and the character body will use move_and_collide multiple times, each time altering the velocity so that it slides against what it’s collided, along with moving platform handling. Then it copies that mutated velocity back to the GDScript velocity we all know and love. So if for any reason you have code is that run in the result of a move_and_collide collision, it may overwrite the velocity. This is fairly uncommon though.
2 Likes
Are you using = or += for your velocity changes?