Hi … how to let enemy know there same thing block his sight to see player
im using “vector3.angle” to make enemy sight
Hi … how to let enemy know there same thing block his sight to see player
im using “vector3.angle” to make enemy sight
void Update() {
//ray shooting from my position towards enemy
Ray ray = new Ray (transform.position, enemy.position - transform.position);
//this object will hold the info of the hit that will occure:
RaycastHit hit = new RaycastHit ();
//do the ray shooting and store the outcome in the 'hit'
Physics.Raycast (ray, out hit);
//if the ray is in the view range (60 deg) of our character:
if(Vector3.Angle(ray.direction, transform.TransformDirection(Vector3.forward) < 30f)
//good, ray is shot forward in 60 degree view range, carry on to the next test
else
//ray's not in 60 degree view range, kill the process
return;
//if the ray hit the enemy:
if(hit.collider.tag == "enemy")
;// saw the enemy, rape him;
else
return; //ray, shot towards the enemy hit something else, kill the process
}