// Update is called once per frame
    void FixedUpdate()
    {
        // Check Velocity > 0 or DIE
        if (Rb.velocity.sqrMagnitude < float.Epsilon)
        {
            ; // TODO: Player Dies
        }
        // Lean
        var leanH = -MaxLeanForce *MassModifier *Input.GetAxis("Horizontal");

        var leanV = -MaxLeanForce *MassModifier *Input.GetAxis("Vertical");

        if (InvertSideLean)
        {
            leanH *= -1;
        }
        if (InvertFwdLean)
        {
            leanV *= -1;
        }

        var forcePosn = transform.TransformPoint(new Vector3(0, 1, 0));
        var forceDirn = transform.TransformDirection(new Vector3(0, 0, leanH));

        var tilt = Mathf.Acos(Vector3.Dot(transform.TransformDirection(new Vector3(0, 0, 1)), Vector3.up)) - (Mathf.PI / 2.0f);



        if (false && Mathf.Abs(tilt) > (MaxLeanAngle * Mathf.PI / 180))
        {
            Debug.Log("Tilt!!!" + (tilt * 180.0 / Mathf.PI).ToString("N3") + " > " + (MaxLeanAngle * Mathf.PI / 180));
            Rb.AddRelativeTorque(new Vector3(-leanH, 0, leanV), LeanMode); // Lean Left/Right, Forward/Back
        }
        else
        {
            Rb.AddRelativeTorque(new Vector3(leanH, 0, leanV), LeanMode); // Lean Left/Right, Forward/Back
        }
        Rb.AddRelativeForce(new Vector3(-leanV, 0, leanH));               // Move Left/Right

        if (leanH != 0 || leanV != 0)
        {
            Debug.Log("Lean H: " + leanH.ToString("N3") + " , V: " + leanV.ToString("N3"));
        }



        // Brake

        CurrentBrake = MaxBrakeForce * Input.GetAxis("Brake");

        Rb.drag = Mathf.Max(InitialDrag, CurrentBrake);

        if (CurrentBrake != 0)
        {
            Debug.Log("Brake: " + CurrentBrake.ToString("N3"));
        }
    }
Пример #2
0
    private void Update()
    {
        checkModules();

        if (condition == ShipCondition.error)
        {
            return;
        }

        //to bootup
        else if (condition == ShipCondition.booting)
        {
            GoFlight();
            return;
        }

        //NORMAL BEHAVIOR
        //		6.	Is there a target?


        //			a. If yes, Nav to Target
        //		7.	Is there a Nav Destination?
        //			a. if no, anchor ship
        //		8.	Cruise to Destination
        if (condition == ShipCondition.active)
        {
            // DRAG CONTROL
            Rb.drag = normalDrag;


            float velocityIntent = throttle * maxSafeVelocity;
            if (Rb.velocity.magnitude < velocityIntent)
            {
                Rb.AddRelativeForce(Vector3.forward * (EnginePower * throttle * mass));
            }

            velocityReport = Rb.velocity.magnitude;

            //point ship toward gyro


            //gimbal causes the ship to keep up with Gyro
            GimbalAction();
            // transform.Rotate(PitchIntensity, YawIntensity, 0f, Space.World);

            Vector3 te = transform.rotation.eulerAngles;
            Vector3 ge = Gyro.transform.rotation.eulerAngles;

            float xr = Mathf.LerpAngle(te.x, ge.x, Time.deltaTime);
            float yr = Mathf.LerpAngle(te.y, ge.y, Time.deltaTime);

            transform.rotation = Quaternion.Euler(xr, yr, 0f);
        }
    }
Пример #3
0
 public void AddRelativeForce(Vector2 force, ForceMode2D mode = ForceMode2D.Impulse)
 {
     Rb.AddRelativeForce(force, mode);
 }