How to tell which direction a player is moving across an object

I’m scripting a skating game, and to make a grinding system, I need to detect which direction the player is moving across the rail

After I detect which direction they’re going across the rail, I can lock the player onto the rail

The video above shows me trying to go straight on the rail (pretty difficult to do at the moment)

My first thought would be to use the lookVector of the HumanoidRootPart, but I have no idea where to begin with this

Humanoid.MoveDirection gives u the direction that the player is trying to move towards

1 Like

https://developer.roblox.com/en-us/api-reference/property/Humanoid/MoveDirection

1 Like
			if OnRail then
				local HRPlookVector = HRP.CFrame.lookVector
				local RailForward = Rail.CFrame.lookVector -- rail's lookvector
				local RailBackward = Rail.CFrame.lookVector * -1 -- rail's backvector
				
				if (HRPlookVector - RailForward).Magnitude < (HRPlookVector - RailBackward).Magnitude then
					print("Right")
					GrindDirection = "Right"
				else
					print("Left")
					GrindDirection = "Left"
				end
				
			else
				GrindDirection = nil
			end

I wasn’t quite sure how to use MoveDirection in this context, but I did figure this out eventually. I checked the magnitude between the HumanoidRootPart’s lookVector and the rail’s lookVector

If Humanoid.MoveDirection can provide a more efficient or accurate way to detect the direction the player moves across the rail, I’m open to change