示例#1
0
    void FixedUpdate()
    {
        //calculate what frame it is
        t = numUpdates * Time.deltaTime;

        if (moving)
        {
            if (useDrag)
            {
                newD = PhysicsCalculator.calculateDistanceDrag(currentD, oldV, Time.fixedDeltaTime, dragConstant);
                newV = PhysicsCalculator.calculateVelocityDrag(oldV, acceleration, Time.fixedDeltaTime, dragConstant);

                if (t >= dt)
                {
                    moving = false;
                }
            }
            else
            {
                newD = PhysicsCalculator.calculateDistance(currentD, acceleration, oldV, Time.fixedDeltaTime);
                newV = PhysicsCalculator.calculateVelocity(oldV, acceleration, Time.fixedDeltaTime);

                if (t >= time)
                {
                    moving = false;
                }
            }

            timeText.text     = "Time: " + t + " seconds";
            frameText.text    = "Frame: " + numUpdates + " frames";
            velocityText.text = "Velocity: " + oldV + " m/s";
            distanceText.text = "Distance: " + currentD + " m";
        }

        //need to recheck if moving before going to next frame.
        //moving could be changed to false before it reaches here so need to recheck.
        if (moving)
        {
            boat.transform.Translate(Vector3.forward * oldV * Time.deltaTime);
            currentD = newD;
            oldV     = newV;
            numUpdates++;
        }
    }