Move Speed is faster on diagonal movements

After adding my movement script in godot. It seems the move speed is a lot faster when moving diagonally. (IE. up and to the right or down and to the right(left)). Just wondering what is causing this as the velocity doesn’t show an increase other than it showing both the x and y vector.

thank you,

1 Like

I haven’t done this course yet, but could it be that it sees the move as one move unit?

Diagonally would be a slightly longer distance than any of the cardinal directions, so if it sees the movement as one move unit, it would traverse that slightly longer distance in the same time span as a cardinal direction move?

If it makes sense?

1 Like

I did end up finding out why it does it on another forum. It seems it has something to do with the way vectors are calculated and using the two numbers on a diagonal ends up adding about 40% more move speed. I have to normalize something to make it work properly. I don’t fully understand it all yet so I’m continuing on until I have completed this section.

2 Likes

Hi Slothmonger,

You are actually pretty correct its about 41% increase.
When you finally calculate the movement you need to normalise the velocity and then multiply by speed.

direction = velocity.normalize()
move_and_slide(direction * speed)

This would limit the velocity to a value between 0 and 1

I found this thread on reddit that may help the understanding a little better

https://www.reddit.com/r/godot/comments/10wj72a/if_i_move_diagonally_the_character_moves_faster/

3 Likes

Hi Marc,
Thank you very much for your help, this helped me to understand the vector2’s and normalization a lot. I found the fault in my script (in comparison to the course). I was calling the move_and_slide() after each if statement instead of at the end of the function. I guess that because of this my velocity Vector2 wasn’t resetting to 0,0 before the move_and_slide() was called which created the odd speed when pressing two directions at once. The way the code was shown in the course it seems that normalization isn’t required.
Thanks again

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms