[RESOURCE] Godot-Style Input System for Roblox (Built on InputActions Beta)
Hey everyone, I very recently started making games on Roblox, and since I’m used to how Godot handles inputs, I made an input library that feels similar built on Roblox’s new InputActions Beta Feature. If you have any feature requests or bugs, message me, comment or whatever.
How To Use This?
Setup
Place your InputContext, InputAction, and InputBinding instances inside this module script.
Example Structure:
InputModule
├─ InputContext (instance of InputContext)
│ ├─ MoveLeft (InputAction)
│ │ └─ KeyboardBinding (InputBinding)
│ ├─ MoveRight (InputAction)
│ │ └─ KeyboardBinding (InputBinding)
│ └─ Jump (InputAction)
│ └─ KeyboardBinding (InputBinding)
Loading the Module
local Input = require(path.to.InputModule)
Most Important Stuff
Check if an action is continuously pressed:
if Input.IsActionPressed("Jump") then
print("Jumping!")
end
Check for a one-time press:
if Input.IsActionJustPressed("Fire") then
print("Fire button was just pressed")
end
Check for a one-time release:
if Input.IsActionJustReleased("Fire") then
print("Fire button was just released")
end
Axis and Vector Inputs
Use for movement or directional input:
local moveX = Input.GetAxis("MoveLeft", "MoveRight")
local moveY = Input.GetAxis("MoveDown", "MoveUp")
local moveVector = Input.GetVector("MoveLeft", "MoveRight", "MoveDown", "MoveUp")
Mouse Inputs
local mousePos = Input.GetMousePosition()
local mouseDelta = Input.GetMouseDelta()
local scrollDelta = Input.GetMouseWheelDelta()
Device Data
local acceleration = Input.GetDeviceAcceleration()
local gravity = Input.GetDeviceGravity()
local rotation = Input.GetDeviceRotation()
Rebinding Actions
Input.RebindAction("Jump", "KeyboardBinding", Enum.KeyCode.Space)
Note: You can’t rebind combined actions created with AddAction. It’ll yell at you.
Check if Any Input is Pressed
if Input.IsAnyPressed() then
print("Some input is being held down")
end
Custom Combined Actions
You can now register your own custom actions that activate when multiple keys are pressed together, like Shift+W for sprinting or Ctrl+R for a shortcut.
Adding a Combined Action:
Input.AddAction("SprintForward", {Enum.KeyCode.LeftShift, Enum.KeyCode.W})
Now you can check it like any other action:
if Input.IsActionPressed("SprintForward") then
print("You are sprinting forward!")
end
Learn more about how to use this, also the RBXM is located in Github releases:
https://github.com/COOKIE-POLICE/input