Anti Gravity Force making player fly instead of levitating in the air

So I have an Anti-gravity script that’s supposed to keep the character in the air, but it does this instead.

This is the code used to create the anti gravity.

local function addAntiGravity(model)
	local bodyForce = Instance.new("BodyForce")
	bodyForce.Name = "AntiGravity"
	local totalMass = 0
	
	for _, v in pairs(model:GetDescendants()) do
		if v:IsA("BasePart") then
			totalMass += v:GetMass()
		end
	end
	
	bodyForce.Force = Vector3.new(0, totalMass * workspace.Gravity, 0)
	bodyForce.Parent = model.PrimaryPart
	return bodyForce
end

In the main script I just do,

local antiGravity = addAntiGravity(character) -- this creates and adds the anti gravity to the HumanoidRootPart

How can I fix this?

1 Like

I would use a BodyPosition instead of a BodyForce for this.

Do I just replace the force with a BodyPosition then? Which properties would I use?

No, you will need to change a couple of things: BodyPosition | Documentation - Roblox Creator Hub

How would I keep the character in the air though? Which properties would I use?

You change the position property of the BodyPosition to the position you want the player to be at. You will likely need to tweak some of the other properties to make it to your liking.

D is dampening, P is power. If your dampening is too low, it will move the character more erratically. If your power is too low, the mover will struggle to move the character.

Now my character can’t move. I want the character to be able to move whilst in the air.

Change the MaxForce on the X and Z axis to 0

1 Like