I'm confused about BodyVelocity

Hello! Can someone explain BodyVelocitys/Velocitys please? I don’t really understand them. I did read the DevHub article about them, but they are pretty confusing.

1. So why do people set the BodyVelocity.MaxForce to math.huge or a huge number?
2. How to make a BodyVelocity move to a certain position? For example the Baseplates position?

Thank you!

8 Likes

BodyVelocity’s apply a force on an object to make it move at a certain velocity. A force is the mass of an object multiplied by its acceleration. When you want to be sure that a force will move an object of unknown mass, or when you want the change in velocity to happen instantly, you typically set MaxForce to a really large number. This way, an object of any mass will accelerate from any unknown velocity to the intended velocity instantly.

Edit: MaxForce summary: The MaxForce determines how long it takes for the object to reach the velocity you specify, and a heavier/larger object will require a greater MaxForce to reach the same velocity in the same amount of time as a lighter/smaller object.

BodyVelocity probably isn’t the best way to make a part move to a certain position (AlignPosition would probably be best-suited for that). However, you could probably use the difference in positions between the part you want to move (let’s call it PartA) and the part you want to move to (PartB) to move PartA to PartB:

local distanceBetween = PartB.Position - PartA.Position
BodyVelocity.Velocity = distanceBetween
-- loop until PartA is at PartB's position

Note that the script I’ve created does not have a maximum velocity, and it does not have an equal velocity on all axes. You could do something more complicated to get a constant velocity, but you’d almost certainly be better off using AlignPosition or BodyPosition.

14 Likes