Пример #1
0
    public override void Act(NPCAI npc, Scannable target)
    {
        NavMeshAgent agent = npc.GetComponent <NavMeshAgent>();

        //Debug.Log("isStopped" + agent.isStopped);
        IsMoving = !agent.isStopped;
    }
    private void SetAttackTarget(NPCAI npc, GameObject target)
    {
        AttackAnimationEventHandler handler = npc.GetComponent <AttackAnimationEventHandler>();

        if (handler == null)
        {
            throw new System.Exception("The npc " + npc.name + " does not have an AttackAnimationEventHandler attatched.");
        }

        handler.target = target;
    }
Пример #3
0
    public override void Cease(NPCAI npc, Scannable target)
    {
        NavMeshAgent agent = npc.GetComponent <NavMeshAgent>();

        if (agent == null)
        {
            throw new System.Exception(npc.name + " is trying to use the NavigateTowards behavour without having a NavMeshAgent");
        }

        agent.ResetPath();
    }
Пример #4
0
    /// <summary>
    /// Sets the NavMeshAgent destination to the position of the target, if it exists.
    /// </summary>
    /// <param name="npc"></param>
    /// <param name="target"></param>
    private void NaviagteTowardsTarget(NPCAI npc, Scannable target)
    {
        NavMeshAgent agent = npc.GetComponent <NavMeshAgent>();

        if (agent == null)
        {
            throw new System.Exception(npc.name + " is trying to use the NavigateTowards behavour without having a NavMeshAgent");
        }

        agent.speed = moveSpeed;
        agent.SetDestination(target.transform.position);
    }
    public override void Plan(NPCAI npc, Scannable target)
    {
        float distance = Vector3.Distance(npc.transform.position, target.transform.position);

        //if scary thing is within avoid set new path directly away from scary thing
        if (distance < avoidDistance)
        {
            Vector3 dirToScare = npc.transform.position - target.transform.position;

            agent = npc.GetComponent <NavMeshAgent>();

            agent.speed = moveSpeed;
            agent.SetDestination(npc.transform.position + dirToScare);
        }
    }