Beispiel #1
0
    void SeekPawn(pawn target)
    {
        agent.SetDestination(target.tf.position);
        Vector3 desiredVelocity = agent.desiredVelocity;

        //desiredVelocity=Vector3.ClampMagnitude
        desiredVelocity = pawn.tf.InverseTransformDirection(desiredVelocity);
        pawn.Move(new Vector2(desiredVelocity.x, desiredVelocity.z));
        //desiredVelocity = tf.InverseTransformDirection (desiredVelocity);
        anim.SetFloat("Horizontal", desiredVelocity.x);
        anim.SetFloat("Vertical", desiredVelocity.z);
    }
Beispiel #2
0
 // Update is called once per frame
 void Update()
 {
     if (pawn != null)
     {
         //get position of the controller
         Vector3 controllerposition = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
         //limit the diagonals
         controllerposition = Vector3.ClampMagnitude(controllerposition, 1.0f);
         //convert so forward on controller is forward in world (based on rotation of the player)
         controllerposition = pawn.GetComponent <Transform> ().InverseTransformDirection(controllerposition);
         //telling pawn to move in that direction
         pawn.Move(new Vector2(controllerposition.x, controllerposition.z));
     }
     if (Input.GetKeyDown(KeyCode.Q))
     {
         pawn.Die();
     }
     RotatetoMouse();
 }