Raycast only fires facing down, ignoring orientation parameter

I’m trying to detect if a raycast from a specific part hits an object facing in front of it. After setting up a raycast every single result has turned out to be with the raycast pointing directly down for some reason. Not only that, but the raycast seems to return a nil value if the orientation is specific values.

-- chr is a given player's Character
local walljumpray = WS:Raycast((chr.HumanoidRootPart.Position) + (chr.HumanoidRootPart.CFrame.LookVector), chr.HumanoidRootPart.Orientation)

Please let me know if more context is needed, I just can’t figure out how to summarize this problem I’m having.

Raycasts take 3 inputs, the origin, direction, and params. Right now, you’re raycasting from in front of a humanoid to an offset equal to whatever the orientation is (e.g. in your original code, if the origin of the raycast was at (0,0,0), and the lookvector was (1,0,0), and the orientation was (90,0,0), you would be trying to raycast to the position (91,0,0)).

Orientation and rotation is actually not a factor in raycasts. Calculating the direction might have rotation, but when you feed in the parameters, it’s all just positional data. To fix the issue you’re having, remove the orientation part of the raycast and use the lookvector instead:

local rootPart = chr.HumanoidRootPart
local walljumpray = WS:Raycast(rootPart.Position, rootPart.CFrame.LookVector)

TLDR: Raycasts take 2 positions as arguments, first the origin, then the offset from the origin. Rotational data is never fed into raycast calls

1 Like