Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to edit the gravitational force being applied to a player (Weight)?

Asked by
RedCombee 585 Moderation Voter
9 years ago

I've seen people do this in admin commands, and I was wondering how to do it for future reference.

0
Scripting, not Building helpers. Tesouro 407 — 9y

2 answers

Log in to vote
3
Answered by 9 years ago

You can just use a BodyForce object to help you counter the force of gravity.

BodyForce applies a constant force on an object. You probably don't know what force is, so I'll explain the basics.

Force is the acceleration multiplied by the mass of an object. The force of gravity then is the gravitational acceleration constant multiplied by the mass of the part.

On ROBLOX, the gravitational constant is equal to 196.2. You can get the mass of a part by using the method GetMass. But, keep in mind that gravity pulls an object downwards. This means we will need a negative sign. So, assuming the variable Part refers to your target Part...

ForceOfGravity = -196.2 * Part:GetMass() -- acceleration multiplied by mass

So how can you use this to your advantage?

If you know the force of gravity, you know the force you need to counteract it.

To completely counter the force of gravity, just insert a BodyForce with the Y component of the force property to the negative of the force of gravity. This will cancel it out because the net force is the sum of all of the forces, so ForceOfGravity + (-ForceOfGravity) = 0.

Instance.new("BodyForce", Part).force = Vector3.new(0, -ForceOfGravity, 0)

But that counteracts gravity for a part. All you have to figure out is the total mass of the character and recalculate the force of gravity like you did before. Assuming character is a reference to a player's character...

TotalMass = 0
for _, part in pairs(character:GetChildren())
     if part:IsA("Part") then
          TotalMass = TotalMass + part:GetMass()
     end
end

ForceOfGravity = -196.2 * TotalMass

Instance.new("BodyForce", character.Torso).force = Vector3.new(0, -ForceOfGravity, 0)
Ad
Log in to vote
0
Answered by
Defaultio 160
9 years ago

The best way to go about this is to probably use a BodyForce in the Torso or HumanoidRootPart, with X and Z components of 0 and a Y component to assist gravity (a negative Y component) or cancel gravity (positive Y). It will have to be a largish value to work. I suggest starting at around (0, 2800, 0) for a solid jump height and tweaking until you've got the effect you want.

Answer this question