Can someone explain what the "point" on RaycastHit.point is?

Every time I read RaycastHit.point.x, y, or z I get values that make no sense. I’m trying to make heads or tails of what point I’m reading. I though it was the point the ray hit the mesh collider but the numbers I get are way off.

It’s exactly that. What doesn’t make sense about the numbers?

Try setting some object’s transform.position to hit.point, and you should see it follow your cursor exactly.

I suspect one of two things is happening:

  1. you may be expecting the point to be in local space to the collider or something to that effect? hit.point is always in world space.
  2. you may have an invisible (trigger?) collider blocking your raycast
1 Like

The documentation can help: Unity - Scripting API: RaycastHit.point

1 Like

It can help to also print raycastHit.transform.name, in case you missed and hit a wall or something. Another trick is you can create a Cube while in Play mode (iwhich is auto-destroyed when you stop) and move it to that x,y,z. You may notice that it’s directly on some wall, or barely on the edge of a pillar. Another crude trick is “square selecting” around the hit, which might highlight an invisible collider you didn’t realize was there.

1 Like

Thanks, tried that. It keeps hitting CustomRightHand (where the script is attached) and not the ray out. That explains the weird values. Don’t know how to fix it but at least I’ve got an idea what’s going on.

Raycasts have one odd rule that works in your favor – they don’t hit things that they start inside. Normally that means the best way to shoot a power bolt from your hand is to raycast from the center. Your hand can never lbock it. I’m not sure if that also works for concave colliders (where a ray could leave your palm but hit a finger). The problem might be that the origin is the end of the arm, just before the hand collider starts?

If I’m serious about tracking these down, I’ll make a red ball and add redBall.position=ray1.start;. and a green ball at the hit point, and the drawRay for good measure. It’s a variant of the old “when things aren’t working, something has the wrong value, so print everything”.