Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1.     protected void UpdateFleeState()
  2.     {
  3.         //Set the target position as the player position
  4.         destPos = playerTransform.position;
  5.  
  6.         //Check the distance with the player tank
  7.         float dist = Vector3.Distance(transform.position, playerTransform.position);
  8.  
  9.         if (dist <= 200.0f && health <= 200)
  10.         {
  11.             //Rotate to the target point
  12.             /*            Vector3 rot = playerTransform.rotation.eulerAngles;
  13.                         rot = new Vector3(rot.x, rot.y + 180, rot.z);
  14.                         transform.rotation = Quaternion.Euler(rot);*/
  15.                        
  16.             Quaternion targetRotation = Quaternion.LookRotation(destPos - transform.position);
  17.             transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * curRotSpeed);
  18.  
  19.             //Go Forward
  20.             transform.Translate(Vector3.forward * Time.deltaTime * curSpeed);
  21.         }
  22.         curState = FSMState.Patrol;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement