Weird Raycasting Angle

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to make a ray that shoots from a player’s hrp
the ray is meant to ignore transparent parts (and parts inside the shooter’s character), but I already have a script for that

  1. What is the issue? Include screenshots / videos if possible!

Whenever I shoot the raycast, it comes out at a weird angle the less distance I apply to it:

In this image I try to shoot a raycast and a brick from the player’s hrp using the same method (hrp.CFrame * CFrame.new())

The brick is shown like it should, but the raycast hits the arm (as shown in the output), which shouldn’t happen. While sometimes it doesn’t even hit anything even though I’m looking directly at the dummy (also shown in the output, with the bricks).

Part of the script I’m using to shoot the raycast is this:

res = workspace:Raycast(hrp.CFrame.p,(hrp.CFrame * CFrame.new(0,0,-100 or -2048.5)).p,rcp) -- "or -2048.5" because that was the original range for the ray
print(res)

If anyone could come up with a solution to this, I would really appreciate it.
Any help is well received.

(here’s another showcase of the bug)

Raycast takes an origin and a direction, but you seem to be giving it a position as the second argument.

Try Raycast(hrp.Position, hrp.CFrame.LookVector * 100, rcp)

1 Like

wow, thanks!

It works just like I intended it to, plus now I finally know a use for CFrame.LookVector, tysm!