Making this rocket stop accelerating?

Hey, I’m scripting a rocket that is moved by a VectorForce, and the force is updated every frame with this equation:

force.Force = Vector3.new(0, 1 * power - drag * speed, 0)

where 1 is the throttle (useless for a rocket, since the only throttle it really can be is 1), power is some constant that was predetermined, drag as well, and speed being the current Y velocity of the rocket.

When the rocket runs out of fuel, I want it to be as if the engine cuts off - no more accelerating, but it doesn’t just start falling out of the sky immediately. I want it to retain it’s velocity, but deaccelerate. When the rocket runs out of fuel, the equation changes to:

force.Force = Vector3.new(0, 0-drag*speed, 0)

since there is no power because the engine cut off, I substituted 0 for power. The rocket starts falling out of the sky extremely fast with this.

Every other method that I’ve tried gives the same results, except for this one where the rocket does indeed deaccelerate, but it is not the behavior that I want because the deacceleration slows over time and the rocket eventually stabilizes at a speed:

force.Force = Vector3.new(0, beforeForce - drag*speed, 0)

beforeForce being the current Y force of the VectorForce. I’m thinking of this like controlling a car in games; you let go of W but do not apply any brakes, and it keeps going but eventually comes to a stop. Any support would be appreciated, thanks.

Got it. Had to change it to

force.Force = Vector3.new(0, beforeForce - drag, 0)

for anyone wondering

Did you make speed directionless, or did you keep it with its sign? (With sign is the correct way otherwise you’d accelerate downwards with increasing acceleration).

Also a definition of beforeForce might be useful for anyone wondering

The definition is at the end of the original post, beforeForce is just the current Y force of the VectorForce. In the new equation, the speed variable is not used at all.

I know this is solved but if you’re interested in rocket physics I highly recommend you check out the attempt I made at creating realistic rocket simulations. It uses the delta-v rocket equation, drag equation (with weather), nasa earth atmosphere model, and simulates a spherical orbit in a flat environment.

Thanks for the link, I’ll check it out because I like recreating real-world physics in roblox (even though I suck at it), but for this game the rocket only needs to fly upwards and come back down :wink:

One bit of advice I can give you for that is if you want it to come back down make sure when calculating drag you do velocity * abs(velocity) (because drag is proportional to velocity sqaured) instead of velocity * velocity. I fell for that trap when I first tested it and it literally self destructed after starting to fall :slight_smile:.

The simple reason for this madness is because multiplying numbers by themselves (squaring) will always get you a positive number because both signs are the same. This means that your drag increases your drag exponentially so the rocket will die in a matter of seconds.

Thanks for the advice. In this project though, each rocket has its own predetermined drag value which is somewhat arbitrary and not a whole lot goes into calculating it. The power value is decided by this:

mass*workspace.Gravity*stats[rocket.Parent.Name].ActualPower

where mass is the total mass of the rocket and ActualPower is some number slightly above 1, because since the mass and gravity is negated it only needs to be multiplied by something above 1 to get it to move. In the case of this rocket, the ActualPower value is 1.075 and drag is 25. This gave me a maximum speed of 142 studs per second when going up. I just rely on roblox physics to get it to go down after my solution eventually reaches a force on the Y of 0. Also your link doesnt work :upside_down_face:

What a lot of people do is take an original force and then multiply it by a coefficient each frame so it eventually gets smaller until it reaches near 0 and the vehicle stops accelerating. This is a simpler method and also produces a similar speed curve so I suggest you use it. I’m not really sure how your system works but if it delivers the results then just keep going.

Fixed the link, surviving on coffee rn and forgot to put in the https. I better sleep, bye :slight_smile:.

Thanks for all the tips. Also your rocket github thing is really cool. I noticed we do stage separation in a similar way.