Is there a way to check if player is going backwards (Only backwards)

I already found a script, but its problem that if you turn too fast, it will count as if you walking backwards

I’m using it to prevent running backwards, but as I said, if you turn too fast (to left or right), it will stop running too

local Character = script.Parent

local humanoid = Character:FindFirstChildOfClass("Humanoid")
local hrp = Character:FindFirstChild("HumanoidRootPart")

local PlayerFromChar = game:GetService("Players"):GetPlayerFromCharacter(Character)

game:GetService("RunService").Stepped:Connect(function()
	if humanoid and hrp and PlayerFromChar then
		
		local directive = hrp.CFrame:VectorToObjectSpace(humanoid.MoveDirection)

		if directive.Z > 0 then
			
		end
	end
end)

I think the issue is that you’re comparing the humanoidRootPart’s cframe and not the camera’s when you calculate directive, because the hrp rotates (relatively)slowly behind the camera

So what I have to do?

(eeee12-31209vkj)

Use the :Dot() product,
tl;dr
VectorOne:Dot(VectorTwo) represents if vectors “looking” at the same direction
You could combine it with with HumanoidRootPart.CFrame.LookVector and Humanoid.MoveDirection to see where is character actually moving

3 Likes

What tl;dr means? I don’t really understand what tl;dr means

it means they didnt feel like reading it, but somehow came up with a solution

TL;DR (Too Large; Didn’t Read)
Usually used for a short explanation of the whole text.
It doesnt mean that I didnt read your problem or anything.

Since I can’t test it right now (And not sure when I can, I will mark this as solution for now)
But still thanks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.