I have been working on a custom character controller script, and I wanted to use W and S to go foward and backwards. I have been following the wiki but I am kinda lost on this part.
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')
local ContextActionService = game:GetService('ContextActionService')
local jumping = false
local leftValue, rightValue = 0, 0
local function onLeft(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
leftValue = 1
elseif inputState == Enum.UserInputState.End then
leftValue = 0
end
end
local function onRight(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
rightValue = 1
elseif inputState == Enum.UserInputState.End then
rightValue = 0
end
end
local function onJump(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
jumping = true
elseif inputState == Enum.UserInputState.End then
jumping = false
end
end
local function onUpdate()
if player.Character and player.Character:FindFirstChild('Humanoid') then
if jumping then
player.Character.Humanoid.Jump = true
end
local moveDirection = rightValue - leftValue
player.Character.Humanoid:Move(Vector3.new(moveDirection,0,0), false)
end
end
RunService:BindToRenderStep('Control', Enum.RenderPriority.Input.Value, onUpdate)
ContextActionService:BindAction('Left', onLeft, true, 'a', Enum.KeyCode.Left, Enum.KeyCode.DPadLeft)
ContextActionService:BindAction('Right', onRight, true, 'd', Enum.KeyCode.Right, Enum.KeyCode.DPadRight)
ContextActionService:BindAction('Jump', onJump, true, 'space', Enum.KeyCode.Space, Enum.KeyCode.Up, Enum.KeyCode.DPadUp, Enum.KeyCode.ButtonA)
So this controller only allows you the go left and right and jump. Because after all it is a 2D game, but I wanted to try something and I cant figure out how to script W and S to go foward and backwards.

6 comments
No I mean like the character will move on all planes. So W goes foward, S goes backwards towards the camera, S and D are left and right. Ive already mapped S and D I just cant get W and S mapped
But those are how the default controls are mapped W goes forward, S goes backward, A goes left, and D goes right depending on your camera position. Also 2d games only allow the character to move on two planes. I may be confused on what you are saying.
I want the character to be able to walk down a hall way away from the camera. And then come back towards the camera.
Here is an example of the camera and controls that I scripted
https://www.roblox.com/games/886667756/FightBlox
If you lock the camera in place that would work I think.