Raycasting Issue

Hello,

I am fairly new at working with raycasts and ran into an issue I need help solving. I created the following raycast that projects off of a character I have spawned in the workspace (R6Animator) and is supposed to go towards a point ahead and above the origin. Here is the code I created to do this:

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {workspace.R6Animator}
local rayOrigin = workspace.R6Animator.HumanoidRootPart.CFrame.p
local rayDirection = workspace.R6Animator.HumanoidRootPart.CFrame*CFrame.new(0,20,-30).p
local raycastResult = workspace:Raycast(rayOrigin,rayDirection,raycastParams)
print(raycastResult)

To verify I was pointing in the correct location, I created a part ahead and above the user using this line of code to show the placement of the rayDirection point:

local H = Instance.new("Part")
H.Parent = workspace
H.Position = workspace.R6Animator.HumanoidRootPart.CFrame*CFrame.new(0,20,-30).p

In the image below, the small 2x4 part is what was spawned using the second line of code. The issue with the raycast is where you see the tall part to the right of my spawned character model (in the character’s direction it’s to the back left corner) is where the raycast is pointing.

I’m sure I’m doing something wrong in the raycast handling, I have to be otherwise it’d be projecting in the direction of the 2x4 part. Any ideas?

Thanks!

It looks like I was missing some key components to define. Here is the working code:

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {workspace.R6Animator}
local rayOrigin = workspace.R6Animator.HumanoidRootPart.CFrame.p
local rayDirection = (workspace.R6Animator.HumanoidRootPart.CFrame*CFrame.new(0,20,-30)).p
local raycastResult = workspace:Raycast(rayOrigin,(rayDirection-rayOrigin).Unit*36,raycastParams)
print(raycastResult)