Gravity Flip Help Needed

I’m making a script that switches your gravity, but it doesn’t let me move.

Here’s my script:

local humanoid = Player.Character.Humanoid

local vectorForce = Instance.new("VectorForce",  Player.Character.LowerTorso)
local att = Instance.new("Attachment", Player.Character.LowerTorso)

vectorForce.Attachment0 = att
vectorForce.Force = Vector3.new(0,5000,0)
vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World


humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)


coroutine.wrap(function()
	while task.wait(0.1) do
		local Height = (0.5 * Player.Character.HumanoidRootPart.Size.Y) + humanoid.HipHeight
		local ray = Ray.new(Player.Character.HumanoidRootPart.Position, Vector3.new(0, 1, 0) * (Height + -.1))
		local Hit, Point, Normal, Material = workspace:FindPartOnRay(ray, Player.Character)

		if Material then
			print(Material) -- enum
		end
	end
end)()

coroutine.wrap(function()
	while task.wait(0.1) do
		humanoid:ChangeState(Enum.HumanoidStateType.Running)
		humanoid.Parent.RightFoot.CanCollide = true
		humanoid.Parent.LeftFoot.CanCollide = true
		humanoid.Parent.RightLowerLeg.CanCollide = true
		humanoid.Parent.LeftLowerLeg.CanCollide = true
	end
end)()

It’s because your Humanoid’s feet never move. It’s always pointed downwards.

@EgoMoose has a good explaination on how he made his wall walking system that defies this logic. Which you can find here. It’s kind of complex.

2 Likes

I tried to use that like a hour ago, but it was too complicated for me. Can you help?

Is there a way to just turn the humanoid feet upside down?

It’s not possible to just turn the character upside down because the Humanoid’s character controller just fires a ray directly down for grounding and uses physics based on the down direction instead of looking at the character’s CFrame (this makes custom characters easier I suppose).

There is a lot of code but what you’re trying to do is easy once you find out where you need to modify the code.

Here are some instructions:

  • Open the example game in studio
  • Find StarterPlayerScripts Edit: Maybe starter character scripts
  • Inside there should be a LocalScript
  • Paste this code inside the LocalScript:
-- By BendsSpace
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")

local GravityController = require(game:GetService("ReplicatedStorage"):WaitForChild("GravityController"))
local Controller = GravityController.new(Players.LocalPlayer)

local UP = Vector3.new(0, 1, 0)
local DOWN = Vector3.new(0, -1, 0)

local gravityDirection = UP

function GetGravityUp(self, oldGravityUp)
	-- Return a length one vector in the direction you want gravity
	return gravityDirection
end

Controller.GetGravityUp = GetGravityUp

ContextActionService:BindAction("Flip Gravity", function(action, state, input)
	if not (state == Enum.UserInputState.Begin) then return end
	
	-- Flips gravityDirection
	gravityDirection *= -1
end, false, Enum.KeyCode.G)

The example code uses the G key to flip gravity. You can use whatever method you want by setting the gravityDirection variable or modifying the GetGravityUp function.

1 Like

Nevermind, I dont see a local script in starterPlayerScripts

Make sure to open this game in studio:

and search for a local script named “LocalScript”

You can also search for “ResetGravity” with ctrl shift f and find the script that way (it flips the gravity if the character falls to far too).

It might be in the starter charcter’s scripts.

1 Like

Ok, I pasted it in and now what? I’m bad at local scripts and ray casts right now. Sorry!

edit: nvm i didnt know pressing g did it XD

1 Like

Hey! I need some help again xd… I found out that your controls get inverted when switching gravity, I have a post here. I can’t find anything else so I’d thought I asked you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.