コード例 #1
0
ファイル: Thruster.cs プロジェクト: mochimind/StationUnrest
 private void initalizeMove(float rotationalOffset)
 {
     state            = ThrusterState.Rotating;
     targetRotation   = Angle.RotationAngle(transform.parent, destination, rotationalOffset);
     startingRotation = transform.parent.rotation.eulerAngles.z;
     if (startingRotation > 180)
     {
         startingRotation -= 360;
     }
     curRotation = 0f;
     if (Mathf.Abs(targetRotation) < 3)
     {
         // know when to stop
         state = ThrusterState.Thrusting;
     }
 }
コード例 #2
0
        private void UpdateRotationDirection()
        {
            bool R1 = (_Type == RotorType.FRONT_LEFT) || (_Type == RotorType.BACK_RIGHT);
            bool R2 = (_Type == RotorType.FRONT_RIGHT) || (_Type == RotorType.BACK_LEFT);

            // Check vertical Speed
            ThrusterState T = _Main._States.GetThrusterState();

            if (T == ThrusterState.UPWARDS)
            {
                _RotationDirection = RotorRotationDirection.COUNTER_CLOCKWISE;
            }
            else if (T == ThrusterState.DOWNWARDS)
            {
                _RotationDirection = RotorRotationDirection.CLOCKWISE;
            }
            else if (T == ThrusterState.STILL)
            {
                if (R1)
                {
                    _RotationDirection = RotorRotationDirection.CLOCKWISE;
                }
                else if (R2)
                {
                    _RotationDirection = RotorRotationDirection.COUNTER_CLOCKWISE;
                }
                else
                {
                    _RotationDirection = RotorRotationDirection.NULL;
                }
            }
            else
            {
                _RotationDirection = RotorRotationDirection.NULL;
            }
        }
コード例 #3
0
        public void UpdateStates(ref Quadcopter.Settings Settings)
        {
            // Thrusters
            thrusters = QuadcopterControls.GetAnalog(Settings._ThrusterControl);

            if (thrusters < 0.0f)
            {
                thrusterState = ThrusterState.DOWNWARDS;
            }
            else if (thrusters > 0.0f)
            {
                thrusterState = ThrusterState.UPWARDS;
            }
            else if (Settings._ThrusterRest)
            {
                thrusterState = ThrusterState.STILL;
            }
            else
            {
                thrusterState = ThrusterState.OFF;
            }

            // Pitch
            float Pitch = QuadcopterControls.GetAnalog(Settings._PitchControl);

            if (Pitch < 0.0f)
            {
                pitchrotation = PitchRotation.CCW;
            }
            else if (Pitch > 0.0f)
            {
                pitchrotation = PitchRotation.CW;
            }
            else
            {
                pitchrotation = PitchRotation.NONE;
            }

            // Yaw
            float Yaw = QuadcopterControls.GetAnalog(Settings._YawControl);

            if (Yaw < 0.0f)
            {
                yawrotation = YawRotation.CCW;
            }
            else if (Yaw > 0.0f)
            {
                yawrotation = YawRotation.CW;
            }
            else
            {
                yawrotation = YawRotation.NONE;
            }

            // Roll
            float Roll = QuadcopterControls.GetAnalog(Settings._RollControl);

            if (Roll < 0.0f)
            {
                rollrotation = RollRotation.CCW;
            }
            else if (Roll > 0.0f)
            {
                rollrotation = RollRotation.CW;
            }
            else
            {
                rollrotation = RollRotation.NONE;
            }

            // Return Euler Changes
            eulerchanges = new Vector3(Pitch, Yaw, Roll);
        }
コード例 #4
0
ファイル: Thruster.cs プロジェクト: mochimind/StationUnrest
    // Update is called once per frame
    void Update()
    {
        /* better approach, will implement later. Also, needed for force based movement
         * // calculate the current angle adjustment required and distance to target
         * Quaternion rotation = Quaternion.LookRotation(destination - transform.position);
         * if (rotation.eulerAngles.z < THRESHOLD) {
         *
         * }
         *
         * // if within thruster angle, apply force
         *
         * // rotate to face the location
         * transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed);
         *
         */
        Debug.Log("State is " + state);
        if (state == ThrusterState.Rotating)
        {
            if (targetRotation < 0)
            {
                curRotation -= rotationSpeed;
                if (curRotation < targetRotation)
                {
                    curRotation = targetRotation;
                    if (faceTargetOnly)
                    {
                        state = ThrusterState.Stopped;
                    }
                    else
                    {
                        state = ThrusterState.Thrusting;
                    }
                }
            }
            else
            {
                curRotation += rotationSpeed;
                if (curRotation > targetRotation)
                {
                    curRotation = targetRotation;
                    if (faceTargetOnly)
                    {
                        state = ThrusterState.Stopped;
                    }
                    else
                    {
                        state = ThrusterState.Thrusting;
                    }
                }
            }

            transform.parent.rotation = Quaternion.AngleAxis(curRotation + startingRotation, Vector3.forward);
        }
        else if (state == ThrusterState.Thrusting)
        {
            transform.parent.position = Vector2.MoveTowards(transform.parent.position, destination, movementSpeed);
            Debug.Log("moving towards" + transform.parent.position + destination + "||" + movementSpeed);
            if (Vector2.Distance(new Vector2(transform.parent.position.x, transform.parent.position.y), new Vector2(destination.x, destination.y)) <= THRESHOLD)
            {
                Debug.Log("stopped");
                state = ThrusterState.Stopped;
            }
        }
    }
コード例 #5
0
ファイル: Thruster.cs プロジェクト: mochimind/StationUnrest
 public void stopMove()
 {
     state = ThrusterState.Stopped;
 }