Hello,
I have a script which makes the enemy follow you if its raycast hits you, and if it is inside a certain zone. There is a cube named “BoundaryCube” that is on the ceiling of the scene.
var thePlayer : Transform;
var centrePoint : Transform;
function Update(){
var hit : RaycastHit;
Debug.DrawRay(transform.position, transform.up, Color.red);
if(Physics.Raycast(transform.position, transform.up, hit)){
if(hit.collider.gameObject.name == "BoundaryCube"){
var targetPosition = thePlayer.position;
targetPosition.y = transform.position.y;
transform.LookAt(targetPosition);
transform.position = Vector3.MoveTowards(transform.position, thePlayer.transform.position, .05);
}
}
}
So when you open a door and go through it, the enemy is supposed to turn around and go back to a game object named CentrePoint because only the main area is covered by the above BoundaryCube.
The problem is not knowing how to make the enemy only look for you IF it is not moving back to the centre.
Does anyone know any code I can use?
Thanks