//updates the bodyguards knowledge of where their vip currently is. We dont want this to be constant in some cases so there are points where the bodyguard //may not be as close to the vip. public void FindVIP() { Vector3 VIPPos = Protect_Client.transform.position; Debug.DrawLine(transform.position, VIPPos, Color.yellow); //Now that we know where the vip is, we want to check the distance between the bodyguard and the vip, if its too far, we reduce the distance between them. //We also want to space the bodyguards out if possible so they position roughly in a circle around the vip. The size of this circle should change //depending on how crowded an area is as well as in relation to the players pursuit of the vip. For now, we randomise the min/max distances the guard //can be from the vip. float dist = Vector3.Distance(transform.position, VIPPos); //if dist is less than the max, we are already within the circle. We also want to make sure the minimum distance is being met. if (dist > max_Dist) { //vip is too far away from the guards maximum allowed distance, we move the guard towards the vip until they are within range. Vector3 fromOriginToObj = transform.position - VIPPos; fromOriginToObj *= max_Dist / dist; //mult by rad , div by dist. Controller.AgentGoTo((VIPPos + fromOriginToObj)); } if (dist < min_Dist) { //bodyguard is too close to the vip, set the bodyguard to wander to a random destination. Controller.SetRandomDestination(); } }
void Patrol() { // Returns if no points have been set up if (Manager.WayPoints.Length == 0) { return; } // Set the agent to go to the currently selected destination. Controller.AgentGoTo(Manager.WayPoints[CurrentWaypoint].transform.position); // Choose the next point in the array as the destination, // cycling to the start if necessary. CurrentWaypoint = (CurrentWaypoint + 1) % Manager.WayPoints.Length; }