I have an object that is constantly right in front of the player, and now I’ve added in an ability for the player to make enemies stop moving by pointing at them with Raycast. I therefore need to make the Raycast coming from the player ignore the object in front of him to make sure the ray won’t just collide with it. I’ve given this object its own layer (layer 10), but the Raycast still collides with it.
This is my code. What have I done wrong?
var Enemy : Transform;
var targetScript01 : FreezeEnemy = Enemy.GetComponent(FreezeEnemy);
var fwd = transform.TransformDirection (Vector3.forward);
var hitInfo : RaycastHit = new RaycastHit();
function Update ()
{
var mask : LayerMask = 10;
var fwd = (Enemy.position - transform.position).normalized;
Debug.DrawRay(transform.position + Vector3(0, 1, 0), fwd, Color.red);
if(Physics.Raycast(transform.position + Vector3(0, 1, 0), fwd, hitInfo, mask.value))
{
if (hitInfo.collider.gameObject.tag == ("Enemy"))
{
targetScript01.Spotted02 = true;
}
else
{
targetScript01.Spotted02 = false;
}
}
}