How to make gravity reverse

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    : I want to be able to switch gravity at press of a button. When I press a button I want a force to pull me upwards.

  2. What is the issue?
    : I can’t figure out how to do that.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    : So far I’ve tried to look in scripts that are similar but I still can’t understand and I’ve searched on the dev forum already and I’ve also tried using VectorForce but it didn’t get to far.

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")

local gravityFlipped = false
local vectorForce = Instance.new("VectorForce") -- Use BodyForce to apply continuous force
vectorForce.Force = Vector3.new(0, 0, 0)
vectorForce.Parent = humanoidRootPart

task.wait(1)

local attPart = Instance.new("Part", character)
attPart.Anchored = true
attPart.size = Vector3.new(0.2,.2,.2)

local att = Instance.new("Attachment", attPart)
vectorForce.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
vectorForce.Attachment0 = att
att.Orientation = Vector3.new(0,0,90)
att.Axis = Vector3.new(-0,1,0)
att.SecondaryAxis = Vector3.new(-1,-0,0)

-- Function to flip gravity
local function flipGravity()
	gravityFlipped = not gravityFlipped

	if gravityFlipped then
		-- Apply upward force equal to the character's weight
		vectorForce.Force = Vector3.new(0, humanoidRootPart.AssemblyMass * workspace.Gravity, 0)
		humanoidRootPart.CFrame = humanoidRootPart.CFrame * CFrame.Angles(math.pi, 0, 0) -- Flip orientation
	else
		-- Remove the upward force
		vectorForce.Force = Vector3.new(0, 0, 0)
		humanoidRootPart.CFrame = humanoidRootPart.CFrame * CFrame.Angles(-math.pi, 0, 0) -- Reset orientation
	end
end

-- Detect when the player presses E
UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end -- Ignore inputs that are already processed
	if input.KeyCode == Enum.KeyCode.E then
		flipGravity()
	end
end)

This is what I tried so far

What happens when using the code you already have? Does the character get rotated correctly?

Looking at the code, you should be multiplying the force by 2. Currently, it only has enough force to keep you from falling due to gravity, however it doesn’t have the force required to move you in the opposite direction of normal gravity.

Right now the Force does not even work, The character just flips for a second and that’s it. I’ll try what you said, thank you!

That’s because the attachment has to be a child of HumanoidRootPart the force will apply to the attachment’s parent not the Constraint’s parent.
Just set the Attachment0 to HumanoidRootPart.RootAttachment

1 Like