Raycast in front of HumanoidRootPart either going too far or not working at all

Usual raycast nonsense. I’ve been trying to get a raycast to go from a player’s HumanoidRootPart in the direction of it’s LookVector by 2 studs but it just doesn’t work no matter how many options I try.

I’ve tried:
local RayInstance = Ray.new(Character.HumanoidRootPart.Position, Character.HumanoidRootPart.CFrame.LookVector * 2)

local RayInstance = Ray.new(Character.HumanoidRootPart.Position, Character.HumanoidRootPart.CFrame.LookVector.Unit * 2)

local RayInstance = Ray.new(Character.HumanoidRootPart.Position, (Character.HumanoidRootPart.Position - Character.HumanoidRootPart.CFrame.LookVector) * 2)

local RayInstance = Ray.new(Character.HumanoidRootPart.Position, (Character.HumanoidRootPart.Position - Character.HumanoidRootPart.CFrame.LookVector).Unit * 2)

I’ve also tried cheating by using attachments at the front of the HumanoidRootPart like so:
local RayInstance = Ray.new(Character.HumanoidRootPart.Position, Character.HumanoidRootPart.Attachment.WorldCFrame * 2)

local RayInstance = Ray.new(Character.HumanoidRootPart.Position, Character.HumanoidRootPart.Attachment.WorldCFrame.Unit * 2)

The raycast method being used here is the deprecated FindPartOnRayWithIgnoreList because I tried using RaycastParams only to find that any table I threw into the FilterDescendantsInstances property would just result in an error of ​Unable to cast value to Object, so instead I opted to use this, however it has worked in the past with this sort of thing so unless some random update has rendered it broken it shouldn’t be causing issues. I’ve additionally tried not using Distance at all in the raycast and instead just filtering the outputs through Distance calculations, likely didn’t work because of the use of FindPartOnRayWithIgnoreList, although it’s hard to check.

My options here are a little scarce so any help at all would be greatly appreciated.

turns out I completely misunderstood my own code and
local RayInstance = Ray.new(Character.HumanoidRootPart.Position, Character.HumanoidRootPart.CFrame.LookVector.Unit * 2) was the correct one to use

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