コード例 #1
0
    private void FixedUpdate()
    {
        // Apply custom gravity to ship.
        Vector3 gravity = NBodySimulation.CalculateAcceleration(rb.position);

        rb.AddForce(gravity, ForceMode.Acceleration);

        // Apply thruster force.
        Vector3 thrustDir = transform.TransformVector(thrust);

        rb.AddForce(thrustDir * thrustMultiplier, ForceMode.Acceleration);

        // Rotate while airborne
        if (numCollisionTouches == 0)
        {
            rb.MoveRotation(smoothRotation);
        }

        // Check if the pilot is outside of the ship.
        if (FindObjectOfType <FirstPersonController>() != null)
        {
            // If so, check the distance between the ship and pilot.
            if (Vector3.Distance(FindObjectOfType <FirstPersonController>().transform.localPosition, transform.localPosition) < 3f)
            {
                shipInRange = true;
            }
            else
            {
                shipInRange = false;
            }
        }
    }
コード例 #2
0
    void FixedUpdate()
    {
        // Gravity
        Vector3 gravity = NBodySimulation.CalculateAcceleration(rb.position);

        rb.AddForce(gravity, ForceMode.Acceleration);

        // Thrusters
        Vector3 thrustDir = transform.TransformVector(thrusterInput);

        rb.AddForce(thrustDir * thrustStrength, ForceMode.Acceleration);

        if (numCollisionTouches == 0)
        {
            rb.MoveRotation(smoothedRot);
        }
    }