How would i keep the player from using the Z axis?

Hello,

I am currently trying to make a 2.5D fighting game with Roblox but I’ve ran into an issue, I cant seem to disable movement on the Z axis.

I’ve tried scripts from here on the Devforum and elsewhere including YouTube tutorials but nothing seems to work.

The closest I’ve got was making it so the player can only use A, D and the Spacebar, however the issue is that approach depends on the camera angle, and i want the camera to zoom in and zoom out if the players are close or far apart and i want it to zoom a bit if the players are close together, which would mean changing the camera angle which would mean changing the player’s axis.

If anybody knows how to disable this axis and can help out that’d be seriously appreciated

Thank you,
Clown.

(btw i mean this Z axis, sometimes people swap it with the Y axis!)
image

You could disable the default movement systems for the character and create your own which only listens for a/d and spacebar, and only moves the player in the x and y axis.

If you use the code below, you can put it into a local script named ControlScript in StarterPlayerScripts. That will disable the default movement and replace it with this.

With the code below, you’ll want to change the position, images/text of the action buttons for mobile players.


local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")

local Player = game.Players.LocalPlayer

local Jump = false
local LeftDown = false
local RightDown = false


local function JumpAction(ActionName, InputState)
	if InputState == Enum.UserInputState.Begin then
		Jump = true
	elseif InputState == Enum.UserInputState.End then
		Jump = false
	end
end

local function LeftAction(ActionName, InputState)
	if InputState == Enum.UserInputState.Begin then	
		LeftDown = true
	elseif InputState == Enum.UserInputState.End then
		LeftDown = false
	end
end
 
local function RightAction(ActionName, InputState)
	if InputState == Enum.UserInputState.Begin then
		RightDown = true
	elseif InputState == Enum.UserInputState.End then
		RightDown = false
	end
end


ContextActionService:BindAction("Jump", JumpAction, true, Enum.KeyCode.Space, Enum.KeyCode.Space, Enum.KeyCode.Up, Enum.KeyCode.DPadUp, Enum.KeyCode.ButtonA)
ContextActionService:BindAction("Left", LeftAction, true, Enum.KeyCode.A, Enum.KeyCode.Left, Enum.KeyCode.DPadLeft)
ContextActionService:BindAction("Right", RightAction, true, Enum.KeyCode.D, Enum.KeyCode.Right, Enum.KeyCode.DPadRight)

local function Update()
	if Player.Character and Player.Character:FindFirstChild("Humanoid") then --Make sure character exists & is loaded
		if Jump then
			Player.Character.Humanoid.Jump = true
		end
		local MoveDistance = 0
		if LeftDown then MoveDistance += 1 end
		if RightDown then MoveDistance -= 1 end

		Player.Character.Humanoid:Move(Vector3.new(MoveDistance,0,0), false)
	end
end

RunService:BindToRenderStep("Control", Enum.RenderPriority.Input.Value, Update)


1 Like

Good suggestion, However…

As i said:

The script I provided works independently of the camera, zooming in or rotating the camera will not change the character’s movement direction.

1 Like

I’ve judged the book by its cover, your code works, perfectly…

Thank you, It’s appreciated!

1 Like