GameMaker How to limit speed of an object with physics?

Carloskhard

Member
I have a ship which I apply a force to, so it can move. But eventually the aceleration adds and it goes too fast.
How can I change that? I don't want to reduce the velocity of the physics world since I need that speed for other objects or that same one after it get upgrades and can go faster.

Thanks for the help!
 
Last edited:

FrostyCat

Redemption Seeker
Manually check the speed and tone it down as needed.
GML:
if (phy_speed > max_speed) {
    var factor = max_speed/phy_speed;
    phy_speed_x *= factor;
    phy_speed_y *= factor;
}
 

Carloskhard

Member
Manually check the speed and tone it down as needed.
GML:
if (phy_speed > max_speed) {
    var factor = max_speed/phy_speed;
    phy_speed_x *= factor;
    phy_speed_y *= factor;
}
Wow, such an easy solution!
Thanks a lot for this. I was squeazing my brain trying to clap x and y velocities, but since I didn't want diagonal movements to be faster I was trying to use the Sin and Cos of the direction movement of the moment, which was a curious amount of code. This is much cleaner and faster.
Thanks :)
 
Top