November 2018
Beginner
246 pages
5h 23m
English
While our tank is in the Patrol state, we check whether it has reached the destination point. If so, it finds the next destination point to follow. The FindNextPoint method basically chooses the next random destination point among the waypoints defined. If it's still on the way to the current destination point, it'll check the distance to the player's tank. If the player's tank is in range (which we choose to be 300 here), then it switches to the Chase state. The rest of the code just rotates the tank and moves forward:
protected void UpdatePatrolState() { //Find another random patrol point if the current //point is reached if (Vector3.Distance(transform.position, destPos) <= 100.0f) { print("Reached to the destination point\n"+ ...Read now
Unlock full access