Example #1
0
    protected virtual void MoveAround()
    {
        //이동할 포인트가 없는경우 제자리에
        if (pointCount == 0)
        {
            SetIdleAnimation();
            return;
        }

        SetWalkAnimation();
        if (movingNum == -1)
        {
            int rand = Random.Range(0, pointCount * 10);
            movingNum = Mathf.FloorToInt(rand * 0.1f);
            agent.SetDestination(points[movingNum]);
        }
        else
        {
            if (agent.remainingDistance < remainingDistanceLimit)
            {
                movingNum = -1;
            }
        }
        stateRot = EnemyRot.FORWARD;
    }
Example #2
0
    void Awake()
    {
        agent     = GetComponent <NavMeshAgent>();
        walkSpeed = agent.speed;
        runSpeed  = walkSpeed * 2;

        animator = GetComponent <Animator>();
        animator.SetTrigger("Idle");
        aniState = EnemyAniState.IDLE;
        state    = EnemyState.NONE;
        stateRot = EnemyRot.FORWARD;
        initMovingPoints();
        chunkPos = chunk.position;
    }
Example #3
0
    protected virtual void Escape()
    {
        if (playerPos == null)
        {
            return;
        }

        SetRunAnimation();
        dir = (transform.position - playerPos.position).normalized;

        switch (stateRot)
        {
        case EnemyRot.FORWARD:
        {
            dirR = Vector3.Cross(dir, transform.up).normalized;
            dirL = -dirR;
            agent.SetDestination(transform.position + dir);
            if (!agent.hasPath)
            {
                stateRot = EnemyRot.RIGHT;
                agent.SetDestination(transform.position + dirR);
                if (!agent.hasPath)
                {
                    stateRot = EnemyRot.LEFT;
                    agent.SetDestination(transform.position + dirL);
                }
            }
        }
        break;

        case EnemyRot.RIGHT:
        {
            agent.SetDestination(transform.position + dirR);
            float angle = Vector3.SignedAngle(dir, dirR, Vector3.up);
            if (!agent.hasPath || angle > 120 || angle < -120)
            {
                stateRot = EnemyRot.FORWARD;
                agent.SetDestination(transform.position + dir);
                dirR = Vector3.Cross(dir, transform.up).normalized;
                dirL = -dirR;
                if (!agent.hasPath)
                {
                    stateRot = EnemyRot.LEFT;
                    agent.SetDestination(transform.position + dirL);
                }
            }
        }
        break;

        case EnemyRot.LEFT:
        {
            agent.SetDestination(transform.position + dirL);
            float angle = Vector3.SignedAngle(dir, dirL, Vector3.up);
            if (!agent.hasPath || angle > 120 || angle < -120)
            {
                stateRot = EnemyRot.FORWARD;
                agent.SetDestination(transform.position + dir);
                dirR = Vector3.Cross(dir, transform.up).normalized;
                dirL = -dirR;
                if (!agent.hasPath)
                {
                    stateRot = EnemyRot.RIGHT;
                    agent.SetDestination(transform.position + dirR);
                }
            }
        }
        break;
        }
    }