Search code examples
c#unity-game-engineraycasting

Unity get XYZ of raycast


I am not sure how to get the coordinates of a raycast. I have looked through the documentation and from what I gathered there is no methods that pull out the specific coordinates from a raycast. How do I go about getting the position of a raycast so other objects can move with it?


Solution

  • Try this:

    RaycastHit hit;
    if (Physics.Raycast(ray, hit)){
        Debug.Log(hit.point)
    }
    
    

    The hit.point is the location where the ray hit (Vector3).