What the title basically says. I’m working on a new car chassis and I want the gravity on it to be reduced so that it doesn’t feel so stuck to the ground, but having to change the gravity of my entire workspace would make everything else in my game feel weird.
So, how can I have gravity affect the chassis less?
I’m guessing I’d need to use VectorForces but I don’t know how to get the right amount of force to apply
Well you could just apply a force pushing in the opposite direction of gravity (increasing normal force if you will). By doing this, you can reduce the effects of gravitational pull in your game.
local gravity = game.Workspace.Gravity
game:GetService("RunService").Stepped:Connect(function(time, step)
local opposingForce = Vector3.new(0, (-gravity / 2) * step, 0)
end)
I believe something like the above should work. In this example, you’re making gravitational force half as strong by applying a force half the magnitude of gravity in the -Y direction. And I believe you could use opposingForce inside a BodyMover like BodyForce, or in VectorForces; whatever works. Let me know if something is wrong with that, however, as I haven’t tested it myself; but that’s the idea at least.
Ah great! That’s the sort of idea I had, and I’m glad you found a way to implement this properly; maybe I’ll use this in the future myself haha. I hope all goes well with your project(s)!
I’ve found a small solution that works. VectorForces seem to be broken even if set up correctly, so I used BodyForce instead.
Here’s some code: BodyForce.Force = Vector3.new(0, part:GetMass() * workspace.Gravity * (1 - g), 0)
where the variable g is a percentage from -1 to 1 (or else things get really wonky)
Remember to both clear the BodyForce’s initial forces and ensure that it is parented to your part.
Full Function that could be used to apply gravity to a given part (serverside obviously)
Here’s a full function that’s pretty much just a copy paste from the official BodyForce page:
local function setGravity(part, g)
local antiGravity = part:FindFirstChild("AntiGravity")
if g == 1 then
-- Standard gravity; destroy any gravity-changing force
if antiGravity then
antiGravity:Destroy()
end
else
-- Non-standard gravity: create and change gravity-changing force
if not antiGravity then
antiGravity = Instance.new("BodyForce")
antiGravity.Name = "AntiGravity"
antiGravity.Archivable = false
antiGravity.Parent = part
end
antiGravity.Force = Vector3.new(0, part:GetMass() * workspace.Gravity * (1 - g), 0)
end
end