How to make inverted controls?

Hello,

The way ROBLOX handles movement of a character is through a class named “ControlModule”. This class spawns a controller object for every player when they join. The controller takes input from a variety of sources such as keyboards, touchscreens and joysticks before translating it into movement.

To be able to invert controls, we want to invert that translation. Luckily for us, the aforementioned controller object has a method called “moveFunction” that it calls after dealing with all the input complexities. We’d only need to invert this moveFunction to invert controls regardless of what the input is coming from. This means our solution would work for every platform that ROBLOX supports such as PC, mobile and Xbox.

With the logic behind the solution understood, we can get to the practicals. To get access to the controller object that have spawned for a particular player, we’d firstly need a local script placed where ever it can work (remember that input from a player and physics on a character are both client-side). To grab the controller object, we need to require the PlayerModule which is automatically generated in PlayerScripts that is inside the Player instance of whomever’s controls we’re intending to invert. The hierarchy looks like so:

Capture

So far, our script would look like so:

local PLAYERS_SERVICE = game:GetService("Players")

local thisPlayer = PLAYERS_SERIVCE.LocalPlayer
local playerScripts = thisPlayer:WaitForChild("PlayerScripts")
local playerModule = require(playerScripts:WaitForChild("PlayerModule"))

After we’ve required the PlayerModule, we need to use one of its methods called GetControls. This will return the movement controller for our player. Our code will now look like this:

--// Everything same from before
local movementController = playerModule:GetControls()

Now we need to invert the moveFunction of the movement controller. By default, the moveFunction is basically the Move function of the Player instance (wiki). Used without the colons (and therefore without implicitly sending the first argument) the function accepts three parameters:

  • Player instance
  • A vector3 movement direction
  • A boolean indicating whether movement is relative to camera or not

To invert movement, we only need to invert the movement direction vector3 which is as simple as multiplying it by -1. So all that we need to do is to wrap the Move function of the Player instance inside a function which inverts this direction. Then we set this inverter function to be our new moveFunction for the movement controller. Our code would look like this:

--// Everthing same from before
movementController.moveFunction = function(player, direction, relative)
    thisPlayer.Move(player, -direction, relative)
end)

That is all. This should invert controls for every platform that ROBLOX supports. To uninvert, or to go back to normal, you’d simply set the moveFunction back to the Move function of the Player instance like so:

movementController.moveFunction = thisPlayer.Move
51 Likes