Why is the raycast firing to the wrong positon

So basically I have a script that fires a raycast right?

Its suppose to go to the grean part.

But is going to where the red part is. Can anyone tell me why this is?

        local po2 = root.CFrame * CFrame.new(0,0,-5)


		local params = RaycastParams.new()
		
		-- direction
		local direction = Vector3.new(po2) - origin
		
		-- send the raycast
		local raycastResult = workspace:Raycast(origin,direction,params)

also the red part goes to raycastResult.Position

If you have an questions tell me

1 Like

try this:

local params = RaycastParams.new()
local raycastResult = workspace:Raycast(root.Position, root.CFrame.LookVector * 5, params)

this should send a ray 5 studs forwards, the way the player is facing. I believe that’s the effect you’re trying to create.

1 Like

This did not work. Its just putting the green part into the void which means its firing in the wrong direction

1 Like

Then try re-orienting the part youre starting the raycast from, or use another face vector (up, left, right, down, back)

1 Like

The distance should only be 5. That code should work assuming the root BasePart is in the position and orientation you expect. I would check that. If that isn’t the problem I would check your code that verifies the raycasts.

2 Likes