How to stop just the x or y of an object?
I am wondering how to apple a stop command to just the x or the y portions of an objects movement. Like if it's moving at an angle just stop it's x and it falls down or just it's y and it goes left, keeping speed of course. Would I have to split the vector of the object, store the part I wanted to save and the stop it altogether and give it the speed at a certain direction?
Re: How to stop just the x or y of an object?
You can use either method.
If you really like to keep it all in direction/speed terms then you can mathematically change the direction and speed to do what you want. I would probably use the separated x and y movement, but it might not be that easy in your case?
Do to it you would kinda have to split it up into x and y movement values and then go back to direction/speed again afterwards.
I made a tiny little example where it calculates the new speed of the object after setting the x-speed to 0 (changes it's direction to down):
http://andersriggelsen.dk/uploads/x-y-split.mfa
As you can see, the object moving left will stop completely on impact while the others will keep a bit of their momentum as they were already moving a bit downwards.
To set the y-speed to 0, then use cos() instead of sin()