Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     if (autopilot.isAutopilotOn())
     {
         Debug.Log(" Rotational Velocity" + rb.angularVelocity.y);
         float currentHeading = ClampTo360(transform.rotation.eulerAngles.y);
         float distance       = GetDistanceAndSetDirection(currentHeading);
         float targetRotVel;
         if (distance < 0.5f)
         {
             targetRotVel = 0;
         }
         else if (distance < 10)
         {
             targetRotVel = 0.3f;
         }
         else if (distance < 60)
         {
             targetRotVel = 0.5f;
         }
         else
         {
             targetRotVel = 1.1f;
         }
         TurnShip(targetRotVel);
     }
 }
Beispiel #2
0
    public void TestAutopilotOn()
    {
        AutopilotModel ap = new AutopilotModel();

        ap.setAutopilotOn(true);
        Assert.IsTrue(ap.isAutopilotOn());
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        if (autopilot.isAutopilotOn())
        {
            //Autopilot Heading Control
            if (rotationalVelocityChange == 0)
            {
                lastRotationalVelocity = rb.angularVelocity.y;
                SetPower(100);
                turnRightButton.onClick.Invoke();
                rotationalVelocityChange = -1f;
            }
            else if (rotationalVelocityChange == -1f)
            {
                rotationalVelocityChange = Mathf.Abs(rb.angularVelocity.y - lastRotationalVelocity);
            }
            else
            {
                float currentHeading = GetCurrentHeading();
                float distance       = GetDistanceAndSetDirection(currentHeading);
                float targetRotVel;
                if (distance < 0.5f)
                {
                    targetRotVel = 0;
                }
                else if (distance < 10)
                {
                    targetRotVel = 0.3f;
                }
                else if (distance < 60)
                {
                    targetRotVel = 0.5f;
                }
                else
                {
                    targetRotVel = 1.1f;
                }
                TurnShip(targetRotVel);
            }

            //Autopilot Speed Control
        }
    }
 // Update is called once per frame
 void Update()
 {
     //Debug.Log (transform.InverseTransformDirection (rb.velocity));
     if (autopilot.isAutopilotOn())
     {
         speedSlider.interactable = true;
         if (autopilotThrusterCounter++ % 2 == 0)
         {
             //Autopilot Heading Control
             //Calculate Rotational Velocity Step 1
             if (rotationalVelocityChange == 0)
             {
                 lastRotationalVelocity = rb.angularVelocity.y;
                 SetPower(100);
                 turnRightButton.onClick.Invoke();
                 rotationalVelocityChange = -1f;
                 //Calculate Rotational Velocity Step 2
             }
             else if (rotationalVelocityChange == -1f)
             {
                 rotationalVelocityChange = Mathf.Abs(rb.angularVelocity.y - lastRotationalVelocity);
                 //Turn ship toward target heading
             }
             else
             {
                 float currentHeading = GetCurrentHeading();
                 float distance       = GetDistanceAndSetDirection(currentHeading);
                 float targetRotVel;
                 if (distance < 0.5f)
                 {
                     targetRotVel = 0;
                 }
                 else if (distance < 10)
                 {
                     targetRotVel = 0.3f;
                 }
                 else if (distance < 60)
                 {
                     targetRotVel = 0.5f;
                 }
                 else
                 {
                     targetRotVel = 1.1f;
                 }
                 TurnShip(targetRotVel);
             }
         }
         else
         {
             //Autopilot Sidedrift Eliminationn
             //Calculate side velocity change
             if (sideVelocityChange == 0)
             {
                 lastSideVelocity = transform.InverseTransformDirection(rb.velocity).x;
                 SetPower(100);
                 strafeRightButton.onClick.Invoke();
                 sideVelocityChange = -1f;
                 //Store side Velocity change
             }
             else if (sideVelocityChange == -1f)
             {
                 sideVelocityChange = Mathf.Abs(transform.InverseTransformDirection(rb.velocity).x - lastRotationalVelocity);
             }
             else
             {
                 float sideVelocity = transform.InverseTransformDirection(rb.velocity).x;
                 SetPower((Mathf.Abs(sideVelocity) / sideVelocityChange) * 100);
                 if (sideVelocity < 0)
                 {
                     strafeRightButton.onClick.Invoke();
                 }
                 else
                 {
                     strafeLeftButton.onClick.Invoke();
                 }
             }
         }
         //Autopilot Speed Control
     }
 }