How can I raycast 2 studs infront of the HumanoidRootPart?

bd8059743ce796d8cdc165e548ca49e6 09e5a3e2c29db0e511f204038ba5f51f

I’m trying to raycast 2 studs infront of the HumanoidRootParts based on its current rotation. I thought it’d be simple but what I have currently doesn’t work at all, it just gets random results.

WorkspaceService:Raycast(UnverifiedPosition, Vector3.new(UnverifiedPosition.X, 0, UnverifiedPosition.Z) * 2, RaycastParams)

CFrame enables you to get a position relative to a direction. (CFrames are quaternions which store both positional and rotational data)

Vectors only store positional data.

Try this out:

local LENGTH = 2

--//LookVector is the forward component of the CFrame, so it'll be the looking direction, hence the name
local rayDirection = humanoidRootPart.CFrame.LookVector.Unit*LENGTH
1 Like

I’m always lost when it comes to CFrame, lol. I should look into getting familiar with it.

Thanks for this. :slight_smile:

1 Like