trying to make it so the player is unable to walk diagonally but only horizontally and vertically, any way to do that??1
Didn’t understand that, you mean, you want to make a 2d player movement? Like to only walk left, right, up and down? Or 3d movement without the ability to walk diagonally in any way?
Its rather simple but might be confusing for a newer dev. I won’t assume anything here. I’ve played around to see if I could overwrite the player movement to disallow diagonal movement and the answer is yes!
local Module = require(game.Players.LocalPlayer.PlayerScripts.PlayerModule)
local controls = Module:GetControls()
controls.moveFunction = function(player, direction, relative)
local modified = direction
if math.abs(direction.X) > math.abs(direction.Z) then
modified = Vector3.new(direction.X,direction.Y,0)
else
modified = Vector3.new(0,direction.Y,direction.Z)
end
game.Players.LocalPlayer.Move(player, modified, relative)
end
Definitely could be written some way better but it serves the purpose here.
You grab the PlayerModule, overwrite the move function with your own, if statement determining whether to move on the X or the Z axis and then move the local player.
(Script located in StarterPlayerScripts)
Yeah exactly like that. Literally stopping them from moving diagonally.
It works! How do I make it fully face the direction tho?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.