Hello! I’m making a gravity switch game but switching gravity invents your controls which can lead to many unfair deaths and angry players. Please help.
you can set the players walkspeed to 0 when upside down then use :Move()
idk if this works lmfao
pretty sure if the walkspeed is 0 Move() wont do anything
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.
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.
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?
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 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:
edit: Its the line with “local left” and the 2nd line with “local forward” for the invert
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!
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
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)
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.