Why to precise velocity.y and not simply velocity?


I Nathan I don't understand why you use velocity.y = move_and_slide_with_snap(...).y,

and not velocity = move_and_slide_with_snap(...)?

I tried the two and didn't notice any changing within the player movement.

1 love
  • Nathan Lovato replied

    With the project's code, if I recall correctly, your suggestion would make enemies get stuck on walls, as they rely on their current velocity to change direction. Only resetting the Y velocity prevents that bug.

    1 love
  • R
    RMDS replied

    Thank you Nathan! I tested with the enemy and yes it is exactly as you said!