Hello, I am trying to make a 2D Movement System. The Character Turns Left When Pressing the “A” Key on the Keyboard. But It Doesn’t Work When Moved To The Left Side On The Mobile Joystick.
i no can send screenshot or video please test code
Code:
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if math.round(Humanoid.MoveDirection.X) == -1 and HumanoidRT then
HumanoidRT.CFrame = CFrame.new(HumanoidRT.CFrame.Position) * CFrame.Angles(0, math.rad(90), 0)
elseif math.round(Humanoid.MoveDirection.X) == 1 and HumanoidRT then
HumanoidRT.CFrame = CFrame.new(HumanoidRT.CFrame.Position) * CFrame.Angles(0, math.rad(-90), 0)
end
end)
This is because the mobile joysticks are analog, so they won’t reach 1 or -1.
so I don’t know what math.round is because that’s new so I’m ignoring it
Why? Because mobile joysticks won’t exactly be 100% X or 100% Y. They are never like that, so you will need to have a greater than / less than operator to determine the move direction instead. Like this: Humanoid.MoveDirection.X < 0
This is because the humanoid is still moving in the Z direction when you use the joystick, even when moving left to right, it is slightly moving in the Z direction.