local function NormalizeVector(vector: Vector3 | Vector3int16 | Vector2 | Vector3int16)
return if (vector.Magnitude == 0) then vector else vector.Unit
end
local currVector = "None"
local Normalize = NormalizeVector(Humanoid.MoveDirection)
Hello, I have a code that determines which way a player is moving. But I don’t know how to display it. I want the currVector to show in letters which way the player is moving, for example: currVector = “Back”, currVector = “Right” and others
Using the values X, Y, and Z that you get from the Function you can figure out which direction the player is moving with some simple if statements.
if normalizedMove.Z > 0 then
currVector = "Forward"
elseif normalizedMove.Z < 0 then
currVector = "Back"
end
if normalizedMove.X > 0 then
currVector = "Right"
elseif normalizedMove.X < 0 then
currVector = "Left"
end
Did I do the right thing? I think I’m processing World Vector
local currVector = "None"
local Normalize = NormalizeVector(Humanoid.MoveDirection)
if Normalize.Z > 0 then
currVector = "Forward"
elseif Normalize.Z < 0 then
currVector = "Back"
end
if Normalize.X > 0 then
currVector = "Right"
elseif Normalize.X < 0 then
currVector = "Left"
end
Just tested in Studio and it is working, must have been due to the if statements.
local function NormalizeVector(vector: Vector3)
return if vector.Magnitude == 0 then vector else vector.Unit
end
RunService.RenderStepped:Connect(function()
local currVector = "None"
local moveDirection = NormalizeVector(humanoid.MoveDirection)
if moveDirection.Z < 0 then
currVector = "Forward"
elseif moveDirection.Z > 0 then
currVector = "Back"
elseif moveDirection.X > 0 then
currVector = "Right"
elseif moveDirection.X < 0 then
currVector = "Left"
end
print("Player is moving: " .. currVector)
end)