Physics.Raycast...

I have some questions about a Physics.Raycast intersection:

1: How do you check the name/tag of the the collider that the raycast hits (is it just like checking a normal collider)?

2: If it does not hit the specified collider name/tag, how can you have it just keep going(until it does hit a collider of the specified tag/name)?

3: How can you get the intersections position so you can move an object to that point?

Hi! I’m not the most experienced guy but let’s give it a try…

var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

if (Physics.Raycast (ray, hit, 1000) ) {

if ( hit.collider.tag == “enemy”) {
print(“Hit enemy!”);
}
}

  1. Not sure if this is doable… You can set colliders to ignore raycast though

  2. Using the hit variable:

Instantiate(goreEmitter, hit.point, transform.rotation);

As for question 2: Use RaycastAll, it returns an array of all hits on the line.