Пример #1
0
    public override void MoveTo(Transform targetTransform)
    {
        if (!canMove)
        {
            return;
        }
        if (currentAvoidState == AIAvoidanceState.Normal)
        {
            Vector3 movement = transform.rotation * Vector3.forward;

            //Rotate towards the transform
            RotateTowards(targetTransform);

            if (CanMoveForward(aiController.obstacleAvoidanceDistance))
            {
                //Move forward
                rb.velocity = movement * data.forwardMoveSpeed * Time.deltaTime;
            }
            else
            {
                currentAvoidState = AIAvoidanceState.TurnToAvoid;
            }
        }
        else
        {
            Avoidance();
        }
    }
Пример #2
0
 public void ChangeAvoidenceState(AIAvoidanceState newState)
 {
     //setting a state
     currentAvoidanceState = newState;
     //Keep track of the time when in the state.
     lastAvoidanceStateChangeTime = Time.time;
 }
Пример #3
0
    // DoAvoidance - handles obstacle avoidance
    void Avoidance()
    {
        if (currentAvoidState == AIAvoidanceState.TurnToAvoid)
        {
            // Rotate left
            Rotate(true);

            // If I can now move forward, move to stage 2!
            if (CanMoveForward(aiController.obstacleAvoidanceDistance))
            {
                currentAvoidState = AIAvoidanceState.MoveToAvoid;

                // Set the number of seconds we will stay in Stage2
                aiController.exitTime = aiController.avoidanceTime;
            }

            // Otherwise, we'll do this again next turn!
        }
        else if (currentAvoidState == AIAvoidanceState.MoveToAvoid)
        {
            // if we can move forward, do so
            if (CanMoveForward(aiController.obstacleAvoidanceDistance))
            {
                // Subtract from our timer and move
                aiController.exitTime -= Time.deltaTime;
                Move(true);

                // If we have moved long enough, return to chase mode
                if (aiController.exitTime <= 0)
                {
                    currentAvoidState = AIAvoidanceState.Normal;
                }
            }
            else
            {
                // Otherwise, we can't move forward, so back to stage 1
                currentAvoidState = AIAvoidanceState.TurnToAvoid;
            }
        }
    }
Пример #4
0
    public void ChangeAvoidanceState(AIAvoidanceState newState)
    {
        currentAvoidState = newState;

        lastAvoidanceStateChangeTime = Time.time;
    }