Raycasting

Hello. I had a need for their own means to implement Raycasting. Implementation should be able to:

  • Identify the object that collided beam.
  • Determine the point of contact.
  • Get the index of the triangle, which ran the beam.

In general, almost everything that can Raycast of Unity. I would be glad of any help.

Identifying the object that the ray hit and determining the point of contact can be pretty simple :

public GameObject hitObject;
public Vector3 pointOfContact;
private RaycastHit hit;

void Update(){
    if(Physics.Raycast(transform.position,transform.forward,out hit, 1000)){
        if(hit.collider){
            hitObject = hit.collider.gameObject;
            pointOfContact = hit.point;
        }
    }
        else{
            hitObject = null;
            pointOfContact = new Vector3();
        }
    }

Hope this helps.

Thanks for the help. But the question was to write a method like Raycast.

Oh, my bad. I misunderstood your qn.