Find which way a player moves

Hello fellow developers, I’ve been working on a dash system but I want to find which way a player is moving, for example if they are moving backwards and they dash, they will dash backwards or if they’re moving to the right and they dash, they will dash more to the right. Only way I can think of is UserInputService to detect which key they’re holding down but it won’t work for mobile and I doubt its efficent. Any solutions to this?

2 Likes

Well, it depends on what you want ur Movement to be relative to. Let’s say you want it to be relative to the Camera you could use smth like Dot Product -

local Cam = workspace.CurrentCamera
local Humanoid = ("Your humanoid Refrence")

if (Humanoid.MoveDirection:Dot(Cam.CFrame.RightVector) > 0.75) then
	print("MOVING RIGHT")
end
if (Humanoid.MoveDirection:Dot(-Cam.CFrame.RightVector) > 0.75) then
	print("MOVING LEFT")
end
if (Humanoid.MoveDirection:Dot(Cam.CFrame.LookVector) > 0.75) then
	print("MOVING FORWARD")
end
if (Humanoid.MoveDirection:Dot(-Cam.CFrame.LookVector) > 0.75) then
	print("MOVING Backward")
end

Hope this Helps you.

2 Likes

You could use HumanoidRootPart’s LookVector to find the direction player is facing.

print(HumanoidRootPart.CFrame.LookVector)

Thanks it worked just like I wanted it to! Just realized ur a developer of slayers unleashed, glad to have had this opportunity xd