How to create terminal velocity

Roblox has no air resistance, so when a force is applied to an object, it just constantly accelerates. How can you create drag to create terminal velocity, or achieve it in another way, because bodyvelocity can’t restrict weight, so even if you set a velocity, you will accelerate out of control when moving in a downward direction, when you should realistically reach 0 acceleration.

2 Likes

I thought Roblox has a physics engine for this? I’m pretty sure there’s gonna be a friction force between the air molecules and the part.

When I tested it out by applying a constant force for 2 minutes, acceleration stayed the same, not changing at all.

You just answered yourself, you added a force that ignored Roblox physics.

How does it ignore Roblox physics though? Weight was still opposing the force so wouldn’t air resistance?

You’re adding a force that’s constantly, I don’t think it gets affected by Roblox physics. I could be wrong but this is just my perspective.

1 Like

If there’s a constant force directly upwards on an object smaller than the force of weight, the two forces still affect each other and the object will fall down slower.

From my experience, when a character is flung and starts falling it never hits any sort of terminal velocity.

I would look into using a BodyVelocity, with the BodyVelocity.Velocity property set to (0,0,0). I’m not exactly certain of the math that would be needed to set the BodyVelocity.MaxForce and BodyVelocity.P properties to get an exact max speed.

What I think this could do is when the speed starts getting too far from 0,0,0 (stopped) the BodyVelocity would apply more force to try and reach 0,0,0 (stopped).

You could also connect to a velocity changed signal and set the velocity to unitVector * maxVelocity if the magnitude is greater than the maxVelocity.

1 Like

From my knowledge, the only things in the Roblox engine that have any sort of drag are humanoids, however drag applied to humanoids is universal and does not change depending on the cross-sectional area of the humanoid. Realistically, the only way you could simulate terminal velocity in Roblox is by using a logarithmic function which slowly decreases the acceleration until it reaches 0.

2 Likes

In real life, terminal velocity is caused by an initially accelerating object facing an equal force in the opposite direction, resulting in no acceleration. Therefore, all we simply need to do is create a force to counter Roblox’s force of gravity. This can be achieved using a BodyVelocity. Using BodyVelocity.Velocity we can give it a target velocity (the terminal velocity), and using BodyVelocity.MaxForce, we can give it our force needed to counter Roblox’s gravity. The the key with our force is that it must be proportionate to the current velocity and mass of the falling BasePart.

By retrieving the BasePart’s BasePart. AssemblyLinearVelocity, we can acquire the object’s current velocity. We can then multiply it by gravity (196.2 by default, see Gravity for more information) and the object’s BasePart.Mass for our required force.

The object’s velocity is of course continuously increasing as the object accelerates. We could make it so the opposing force is applied as soon as the object reaches terminal velocity. This however may appear visually less realistic as the object will suddenly stop accelerating. Air resistance doesn’t suddenly appear once an object reaches a certain velocity. So alternatively, we could regularly update the opposing force so that it can be applied while the object is also accelerating.

The following shows how this could be scripted. It gives a part a downwards terminal velocity of 100 studs per second:

local part = script.Parent
local bodyVelocity = Instance.new("BodyVelocity") 
bodyVelocity.MaxForce = Vector3.new(0,0,0)
bodyVelocity.Velocity = Vector3.new(0,-100,0) 
bodyVelocity.Parent = script.Parent

while true do
	bodyVelocity.MaxForce = Vector3.new(0,math.abs(part.AssemblyLinearVelocity.Y * 196.2),0)
	print(part.AssemblyLinearVelocity)
	wait()
end

To test, simply put in a script, and parent to a part.

Hope this helps.

You would need a (quadratic) function that defines the strength of an opposing force in function of the objects speed.

Irl this function would change due to the aerodynamics of a construction, I don’t think this can be calculated accurately on roblox. You would need to try some functions and see what feels right.

When you get that force, you can simply subtract it from the force pushing you forwards. (prevent this from going negative/backwards)

This is a video on how you can use a formula to get the velocity of the object and calculate drag from it. I used this force when I was creating a ship movement through water for a new game. This helped me hopefully watching this will help you too :smiley:

The reason why it will create terminal velocity is because at a certain point the drag will eventually cancel out if the Velocity is too fast and it will allow for more slower objects to move faster

The way I implemented a close approximation to drag force in my game without just hard-capping the velocity is by reducing the acceleration by a percentage of the total velocity.

(torso is the HumanoidRootPart, I also use ApplyImpulse to move my characters)

torso:ApplyImpulse(((mathModule.fixVector(camera.CFrame.LookVector) 
	* (F_FORCE + B_FORCE)) 
	+ (camera.CFrame.RightVector * (R_FORCE + L_FORCE))) 
	* CONST_SPEED 

This part is the acceleration (direction and magnitude) ^^^^^^

	- ( Vector3.new(torso.Velocity.X / 2.75, torso.Velocity.Y / 3.5, torso.Velocity.Z / 2.75))
) 

This part here subtracts a percentage of total velocity from that acceleration ^^^^^^

When the player starts picking up too much speed, their amount of acceleration starts to slow down until they reach a point where their speed remains constant.

This also allows me to add speed boosts and extra forces since there’s no hard-capping.

I also didn’t need too much accuracy so I never had to look too much into the math and physics for drag force here, but it might be useful.

https://www.roblox.com/games/6711634328/Project-Cannon

Here’s the game if you want to check it out!

Air resistance force is pretty simple to apply on your own. Here’s an answer I wrote a few years ago detailing how to implement it in Roblox. How do you change air friction? - Scripting Helpers

1 Like