void Avoid()
    {
        if (avoidanceStage == AvoidStage.rotateUntilCanMove)
        {
            motor.Rotate(-1 * data.rotateSpeed);

            if (CanMove(data.moveSpeed))
            {
                avoidanceStage = AvoidStage.moveForSeconds;
                exitTime       = avoidanceTime;
            }
        }
        else if (avoidanceStage == AvoidStage.moveForSeconds)
        {
            if (CanMove(data.moveSpeed))
            {
                exitTime -= Time.deltaTime;
                motor.Move(data.moveSpeed);

                if (exitTime <= 0)
                {
                    avoidanceStage = AvoidStage.notAvoiding;
                }
            }
            else
            {
                avoidanceStage = AvoidStage.rotateUntilCanMove;
            }
        }
    }
 void Chase()
 {
     if (CanMove(data.moveSpeed))
     {
         //move if can move
         if (motor.RotateTowards(target.position, data.rotateSpeed))
         {
             // Do nothing
         }
         else
         {
             motor.Move(data.moveSpeed);
         }
     }
     else
     {
         avoidanceStage = AvoidStage.rotateUntilCanMove;
     }
 }
Beispiel #3
0
    void Update()
    {
        switch (avoidStage)
        {
        case AvoidStage.None:
            //Do Nothing.
            break;

        case AvoidStage.Rotate:
            if (target != null)
            {
                move.RotateTowards(Vector3.right, data.rotateSpeed);
            }
            if (CanMove(data.forwardSpeed))
            {
                avoidStage = AvoidStage.Forward;
            }
            break;

        case AvoidStage.Forward:
            move.Move(data.forwardSpeed);
            if (CanMove(data.forwardSpeed))
            {
                avoidStage = AvoidStage.None;
            }
            else
            {
                avoidStage = AvoidStage.Rotate;
            }
            break;

        case AvoidStage.Error:
            Debug.Log("Obstacle Avoidance failed or is terminated");
            break;
        }
    }