Hi, I’m making a 2.5D type of game, and I need the character’s Humanoid.MoveDirection
to exclusively face one of these directions. This means, the directions can be something like (1,0,0)
or something like (-0.707,0,0.707)
.
I can’t seem to get Analog-type inputs (mobile thumbstick and console) to work properly. They are just changing the MoveDirection to whatever random analog direction the player is facing. PLEASE HELP
What solutions have you tried?
I got it working for keyboard with this script, but mobile and console don’t work:
local function snapPlayerToAxis(plr)
local Character
while not plr.Character do
task.wait()
Character = plr.Character
print(`SnapToAxis :: Waiting for {plr.Name}'s Character`)
end
local hum = Character:WaitForChild("Humanoid")
local rootPart = Character.HumanoidRootPart
hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()--fires when the humanoid's move direction changes
local rootPos = rootPart.CFrame.p--get root position
local moveDir = hum.MoveDirection--get character's move direction
moveDir = Vector3.new(moveDir.X, 0, moveDir.Z)--remove the y component
if moveDir.Magnitude > 0 then--make sure we're not standing still
rootPart.CFrame = CFrame.new(rootPos, rootPos + moveDir)--rotate the player
end
end)
end
for _,plr in game.Players:GetPlayers() do
snapPlayerToAxis(plr)
end
game.Players.PlayerAdded:Connect(function(plr)
snapPlayerToAxis(plr)
end)