How to change the effect of gravity on only certain parts?

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

5 Likes

This is the correct solution. Just experiment with it, really. I used this to recreate the classic paintball gun, seen here.

1 Like

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.

https://www.roblox.com/library/5087142440/Gravity-Modifier
I’ve been waiting to give someone this.

1 Like

Looks like I figured it out myself. I’ll explain:

game:GetService("RunService").Stepped:Connect(function()
	script.Parent.VectorForce.Force = script.Parent.Position + Vector3.new(0, script.Parent:GetMass() * (workspace.Gravity / 1.1), 0)
end)

Where the VectorForce is applied relative to the world so it’s always pushing up no matter the orientation.

Also to calculate the current gravity on the object you’d do gravity - (gravity / gravityCoeff)

So in my example my coefficient is 1.1, and default workspace gravity is 196.2

So (196.2 / 1.1) = 178.3
196.2 - 178.3 = 17.9 studs/second^2

21 Likes

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)!

1 Like

I tried, but it didn’t work, maybe it’s because roblox studio has changed.
Can you send it as rbxl file?

edit–>
I think it worked when I tried this:

script.Parent.VectorForce.Force = Vector3.new(0, script.Parent:GetMass() * (workspace.Gravity / 1.1), 0)

so I just cut x and z positions
or you can use BodyVelocity if you don’t want use attachment

2 Likes

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
3 Likes

can you do meters/second please. I’m trying to get the coefficient for 77

1 Like