Rebinding movement keys

I’m creating a game that follows the traditional Arrow Keys movement and Z, X, C, V controls.
I want to unbind the movement keys from WASD and rebind them to the arrow keys.
I have an isometric camera that cannot be moved.

I’ve tried looking through various sources but I’m having trouble understanding the API reference and any tips from previous forum posts regarding a similar situation. If anyone can help I’ll greatly appreciate it.

2 Likes

Maybe try go to starterplayer and movement mode change it to scriptable, im not sure if it works but that’s all i can think of.

I’ve set that already, I just need help with the script involving the movement.

Try use Player:Move()

I looked around for a bit but then realized this was mainly for just NPCs, and not for player inputs.

it can still be used for player inputs by repeating the movement until they release the key or until you decide to stop it other than that i can just think of Humanoid:MoveTo()

u gotta make ur own movement system. Its not that hard acc. You can use the humanoid Property WalkToPoint and use 1st grade maths to do it! And use contextaction service to bind them.

1 Like

LOCAL SCRIPT in STARTERCHARACTERSCRIPTS

local Char = script.Parent
local Hum = Char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local leftkey,rightkey,upkey,downkey = -- Enum.KeyCode. ? for every key 
local x,z = 0,0

local function Update()
Hum.WalkToPoint = Char:WaitForChild("HumanoidRootPart").Position+Vector3.new(x,0,z)
end

UIS.InputBegan:Connect(function(i,gpe)
if gpe then return end
if i.KeyCode == leftkey then x = -1 elseif i.KeyCode == rightkey then x = 1 end
if i.KeyCode == upkey then y = 1 elseif i.KeyCode == downkey then y = -1 end
end

You get the idea right? The code does has errors btw so fix em. cuz i wrote this in devforum.

2 Likes

Thanks so much man I appreciate it

Yea np. Add

UIS.InputEnded:Connect(function(i,gpe)
if gpe then return end
if i.KeyCode == leftkey then x = 0 elseif i.KeyCode == rightkey then x = 0 end
if i.KeyCode == upkey then y = 0 elseif i.KeyCode == downkey then y = 0 end
end
game:GetService("RunService").Heartbeat:Connect(Update)

at the end of the code to make sure it does not walk forever and does infact work.

You can basically disable the player module that handles controls, thus disabling WASD movement. Then you can connect your own movement code.

local PS = game:GetService("Players")
local UIS = game:GetService("UserInputService")

local player = PS.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local mod = require(player.PlayerScripts:WaitForChild("PlayerModule"))
local controls = mod:GetControls()
local keys = {
	[Enum.KeyCode.Up] = Vector3.new(0, 0, -1),
	[Enum.KeyCode.Down] = Vector3.new(0, 0, 1),
	[Enum.KeyCode.Left] = Vector3.new(-1, 0, 0),
	[Enum.KeyCode.Right] = Vector3.new(1, 0, 0)
}

controls:Disable()

UIS.InputBegan:Connect(function(input, typing)
	if typing then
		return
	end
	
	local key = input.KeyCode
	
	if keys[key] then
		player:Move(keys[key], true)
		
		repeat task.wait() until not UIS:IsKeyDown(key)
		
		player:Move(Vector3.zero, true)
	end
end)
4 Likes