What do you want to achieve?
I want to change a part’s gravity value while keeping the world’s gravity. I’m working on a car that uses a different gravity value and I’m about to publish it as a free model and I want to give the car a different gravity value automatically rather than making an instruction manual that no one will probably read then call it “broken”.
What is the issue?
I don’t know how to change the gravity value of a specific part via script.
local core = script.parent.car.core
local carParts = script.parent.car.core:GetChildren()
local bodyForce = Instance.new('BodyForce', core)
bodyForce.Name = 'Antigravity'
bodyForce.Force = Vector3.new(0, carParts:GetMass() * game.Workspace.Gravity - 20, 0) --lets say the gravity is 80, with this its now 60
I don’t think that’s right. I think it should be this.
Vector3.new(0, carParts:GetMass() * 20, 0)
As a body force, gravity still applies. And the 20 needs to be multiplied by the mass in order to provide adequate force. So this code should reduce gravity by 20.
Ok, so none of the calculations worked, they ended up like this…
Or maybe I didn’t get the code right…
for i, v in pairs(car:GetDescendants()) do
if v:IsA("BasePart") then
local bforce = Instance.new('BodyForce', v)
bforce.Name = 'AG'
bforce.Force = Vector3.new(0, v:GetMass() * game.Workspace.Gravity - 119.2, 0)
end
end
for i, v in pairs(car:GetDescendants()) do
if v:IsA("BasePart") then
local bforce = Instance.new('BodyForce', v)
bforce.Name = 'AG'
bforce.Force = Vector3.new(0, v:GetMass() * 119.2, 0)
end
end
I found another formula from the gravcomp chassis, a modified version of the A-Chassis that uses the realistic gravity preset (Which feels like the moon, hence 77 value from earlier), but I don’t really know how it works.