示例#1
0
    void FixedUpdate()
    {
        if (moving)
        {
            //Calculate tau dynamically to account for mass changes
            tau = PhysicsCalculator.calculateTau(mass_com, dragCoefficient);

            //Calculate the boat's velocity for its forward motion
            vMax  = PhysicsCalculator.calculteTerminalVelocity(force, dragCoefficient);
            newVz = PhysicsCalculator.calculateVelocityWithDrag(vMax, dragCoefficient, oldVz, fixedTime, mass_com);
            newDz = PhysicsCalculator.calculatePositionWithDrag(oldDz, force, dragCoefficient, fixedTime, mass_com, oldVz);

            //Calculate the linear movement acceleration with drag
            accelerationWithDrag = PhysicsCalculator.calculateAccelerationWithDrag(force, dragCoefficient, oldVz, mass_com);

            //Calculate the boat's velocity and acceleration with drag for its angular motion
            oMax  = PhysicsCalculator.calculateTerminalAngularVelocity(turnForce, dragCoefficient);
            omega = PhysicsCalculator.calculateAngularVelocityWithDrag(oMax, dragCoefficient, oldOmega, fixedTime, mass_com);

            //Update the boat's position
            totalBoat.transform.Translate(newVx * fixedTime, 0, newVz * fixedTime);
            totalBoat.transform.Rotate(0, Mathf.Rad2Deg * (omega * fixedTime), 0, Space.Self);
        }

        if (moving)
        {
            numUpdates++;

            //update UI
            timeText.text = "Time: " + ((numUpdates) * fixedTime) + " seconds";
            posText.text  = "Velocity: " + newVz + "m/s";
            angDText.text = "Acceleration " + accelerationWithDrag + " m/s^2";
            disText.text  = "Distance: " + newDz + " m";

            oldDx = newDx;
            oldVx = newVx;
            oldDz = newDz;
            oldVz = newVz;

            oldOmega = omega;
        }
    }