How do I find the character raydirection?

How would I find the characters ray direction?

What do you mean by ray direction? Do you mean move direction as in which direction the player is moving at?

Basically, the raycast direction of a part so I can know which way its facing

You could determine if a player is in front or behind a part by finding its position relative to said part

1 Like

I would but I do not know how to do that.

You can use BasePart.CFrame:ToObjectSpace(HumanoidRootPart.CFrame).Position
to determine direction relative to the part

From this example it determines the player’s position relative to the part and prints if the players humanoidroot part is beyond -Z of a part and another print if behind

local players = game:GetService("Players")
local Main = workspace.MAIN -- any basepart 

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		
		local taskcoro = coroutine.create(coroutine.wrap(function()
			while true do
				local HumRp = char:WaitForChild("HumanoidRootPart")

				local DirectionRelative = Main.CFrame:ToObjectSpace(HumRp.CFrame).Position

				if DirectionRelative.Z < 0 then
					print(plr.Name.." is in front of part")
				elseif DirectionRelative.Z > 0 then
					print(plr.Name.." is behind Part")
				end
				task.wait(.5)
			end
		end))
		
		coroutine.resume(taskcoro)
	end)
end)

If you want to know if the player’s character is directly in front of the part then you could add a condition to make sure the X coordinate of DirectionRelative never exceeds 1 or -1 or any range you choose

1 Like

It sounds like you’re just looking for LookVector, which is a property of CFrame.

LookVector gives you the direction that an object is facing. So you would type “HumanoidRootPart.CFrame.LookVector” in order to see which direction the character is facing.

Here’s a thread from someone asking how LookVector works.

character.PrimaryPart.CFrame.LookVector