Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (target != null)
        {
            if (Vector3.Distance(target.position, transform.position) < radius)
            {
                agent.isStopped = false;
                agent.SetDestination(target.position);
            }
            else
            {
                agent.isStopped = true;
            }
        }



        //Debug.Log(agent.desiredVelocity);
        if (agent.remainingDistance > agent.stoppingDistance)
        {
            //Debug.Log(agent.remainingDistance);
            character.Move(agent.desiredVelocity, agent);
        }
        else
        {
            character.Move(Vector3.zero, agent);

            if (agent.velocity.magnitude == 0)
            {
                character.attack();
            }
        }


        /*
         * if (move == true)
         * {
         *  Debug.Log("moving to " + target_position);
         *  agent.SetDestination(target_position);
         *
         *
         *  if (agent.remainingDistance <= agent.stoppingDistance)
         *  {
         *
         *      stopMoving();
         *      character.Move(Vector3.zero, agent);
         *  }
         * }*/
        /* if (agent.remainingDistance > agent.stoppingDistance && move == true)
         * {
         *
         *   character.Move(agent.desiredVelocity, agent);
         * }*/

        //Debug.Log("remain " + agent.remainingDistance + "stop " + agent.stoppingDistance);
    }
Example #2
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        //Debug.Log(target.transform.position);
        if (target != null)
        {
            if (Vector3.Distance(target.transform.position, NPC.transform.position) < radius)
            {
                agent.isStopped = false;
                agent.SetDestination(target.transform.position);



                //Debug.Log(agent.desiredVelocity);
                if (agent.remainingDistance > agent.stoppingDistance)
                {
                    //Debug.Log(agent.remainingDistance);
                    EnemyCharacter.Move(agent.desiredVelocity, agent);
                }
                else
                {
                    //EnemyCharacter.Move(Vector3.zero, agent);

                    if (agent.velocity.magnitude == 0 && agent.remainingDistance > 0)
                    {
                        //Debug.Log("stop");
                        EnemyCharacter.attack();
                    }
                }
            }
            else
            {
                //Debug.Log("stop");
                agent.isStopped = true;
                EnemyCharacter.Move(agent.desiredVelocity, agent);
            }
        }
    }