How to invert player controls?

I think you can just set the walkspeed to negative. If that doesn’t work though, there should be something in the ControlModule in roblox’s default character scripts that will allow you to change how inputs are translated to movement.

1 Like

Roblox automatically sets Walk Speed to 0 if its negative. So, this wouldn’t work.

I’ll do the ControlModule thing. I put it in the studio, and I don’t know what to do now.

Edit: Nevermind, I found out how

Do you have any way to change the controls when gravity switches? The script that handles gravity is in StarterCharacterScripts.

Try rotating the camera around 180 degress, and maybe will look more cool and fix the problem

Good idea! but I think inverting the controls would be better for now.

1 Like

I believe this solution should work unless the gravity controller heavily modified/replaced the ControlModule.

Are the controls always inverted? Or is it just when the character is in the process of flipping?

1 Like

It is inverted when its flips. I don’t think it changes the control script. However, since the character is flipping, it thinks its that direction. (Sorry for bad explanation I’m kind of dizzy right now.)

I don’t know why, but the gravity controller script (the one in serverscriptservice) completely breaks the invert controls script. I have no idea why though. I’ll see what I can do.

edit: oh, i found out that gravity controller as its own control script. ill see what i can do with that

edit 2: I have no idea what I’m doing.

can you show us the gravity controller script code that controls the movement??

I don’t know what it is. I used this to make the gravity switch. this

I figured how to invert it! However, I don’t really know how to switch controls when gravity changes.

Here’s how I made the invert if you need to know:


Screenshot 2024-02-12 204146

edit: Its the line with “local left” and the 2nd line with “local forward” for the invert

1 Like

Nice! You could create a function inside the gravity controller named something like “GravityController:SetControls(isInverted)” that changes those values (if it’s run on heartbeat you could create a variable outside then use an if statement) then in the LocalScript you pasted (which has access to the character’s GravityController) run the method when you flip the gravity like GravityController:SetControls(true) or GravityController:SetControls(false).

Nice job finding that spot!

1 Like

I’m not exactly sure how to do it. Because the script goes in replicated storage and not the player… Also I don’t know what heartbeat is : /

Ah, yeah, I over complicated that.

Heartbeat is an event that runs every time physics is updated, it’s used for things that need to be continuously updated (like the gravity).

The local script creates an object for the player from the GravityController module, so I was thinking you could modify it and use the new function in the local script:

local GravityController = require(game:GetService("ReplicatedStorage"):WaitForChild("GravityController"))
-- Makes a controller for the player
local Controller = GravityController.new(Players.LocalPlayer)
-- Ex: Controller:FlipControls(true) etc.

Though I realize now that’s overcomplicated.

Instead, since that code runs continuously (on heartbeat), you can just check the direction of the gravity and set it based on that:

	local left = -cForward:Cross(newGravity).Unit
	local forward = -left:Cross(newGravity).Unit
	
	local upVector = Vector3.new(0, 1, 0)
	-- If the gravity is going the opposite direction the dot will be negative (aka the gravity is inverted)
	if newGravity:Dot(upVector) < 0 then
		left = cForward:Cross(newGravity).Unit
		forward = left:Cross(newGravity).Unit
	end

That’s my bad for over complicating that :sweat_smile:

thanks for telling : D! but I am very bad at local scripts and module scripts because I started coding like 3 months ago. (sorry if i’m asking too much)

1 Like

No worries! It goes right where you found the variables:

Paste this

local left = -cForward:Cross(newGravity).Unit
local forward = -left:Cross(newGravity).Unit
	
local upVector = Vector3.new(0, 1, 0)
-- If the gravity is going the opposite direction the dot will be negative (aka the gravity is inverted)
if newGravity:Dot(upVector) < 0 then
	left = cForward:Cross(newGravity).Unit
	forward = left:Cross(newGravity).Unit
end

Right over the lines

local left = -cForward:Cross(newGravity).Unit --  cForward:Cross(newGravity).Unit  put this to invert controls
local forward = -left:Cross(newGravity).Unit --  left:Cross(newGravity).Unit       put this to invert controls

in the GravityController module script in replicated storage.

2 Likes

YO! It works!!! THANK YOU SO MUCH IM ACTAULLY SO HAPPY : D

1 Like

I had this same question but I solved it so please mark this

oh sorry I forgot to send this also I think this works on console and maybe mobile mobile was hard to do…

  1. go to StarterPlayerScripts in StarterPlayer
  2. Add a bool value named “Reversed”
  3. put this script in StarterPlayerScripts:
    ReversedSetup.rbxm (128.2 KB)
1 Like

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