#How do I set a velocity value to just velocity.x?

4 messages · Page 1 of 1 (latest)

small widget
#

I’m not really sure what you mean by “turn velocity into only velocity.x”

If you mean “get rid of all vertical momentum”, you can set velocity.y to 0 and only have horizontal momentum.

#set vertical velocity to 0, so only the x-axis matters
velocity.y = 0;

#

Or do you want to completely convert ALL momentum to horizontal momentum?

In which case, you can create a new vector and set it’s x-value as the length (or the scalar?) of the original vector.

#converts all momentum into strictly horizontal momentum
velocity = Vector2(velocity.distance_to(Vector2.ZERO, 0) if velocity.x > 0 else Vector2(-velocity.distance_to(Vector2.ZERO, 0);

#

What exactly is happening in game, and what do you want to happen?

ionic egret
#

yes you can. If you do velocity.x you only affect the x value