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; } }
void FixedUpdate() { if (moving) { if (numUpdates == 100 && !dynamicControls) { moving = false; } //calculate the new distances and velocities newDx = PhysicsCalculator.calculateDistance(oldDx, acceleration.x, oldVx, fixedTime); newVx = PhysicsCalculator.calculateVelocity(oldVx, acceleration.x, fixedTime); newDz = PhysicsCalculator.calculateDistance(oldDz, acceleration.z, oldVz, Time.fixedDeltaTime); newVz = PhysicsCalculator.calculateVelocity(oldVz, acceleration.z, Time.fixedDeltaTime); if (rotLeft) { temp1 = accelerationL; } if (rotRight) { temp1 = accelerationR; } angularVelocity = oldAngularVelocity + (temp1 * fixedTime); angularDisplacement += Mathf.Abs(angularVelocity * fixedTime); distanceX += newVx * fixedTime; distanceZ += newVz * fixedTime; //------- LAB #7 Additions ------- tau = PhysicsCalculator.calculateTau(mass_com, dragCoefficient); vMax = PhysicsCalculator.calculteTerminalVelocity(force, dragCoefficient); newVz = PhysicsCalculator.calculateVelocityWithDrag(vMax, dragCoefficient, oldVz, fixedTime, mass_com); newDz = PhysicsCalculator.calculatePositionWithDrag(oldDz, force, dragCoefficient, fixedTime, mass_com, oldVz); accelerationWithDrag = PhysicsCalculator.calculateAccelerationWithDrag(force, dragCoefficient, oldVz, mass_com); totalBoat.transform.Translate(newVx * fixedTime, 0, newVz * fixedTime); } if (moving) { numUpdates++; //update UI timeText.text = "Time: " + ((numUpdates) * fixedTime) + " seconds, " + (numUpdates) + " updates"; 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; oldAngularVelocity = angularVelocity; } else { v_final = oldVz; } }