// Use this for initialization void Start() { numUpdates = 0; moving = true; gunBallSpawned = false; initial = true; lastMarker = numUpdates; buffer = 5; fixedTime = Time.fixedDeltaTime; oldVz = gunBallVelocity; range = PhysicsCalculator.calculateRange(boat, target); xDifference = PhysicsCalculator.calculateXDifference(boat, target); collided = false; if (xDifference != 0) { // gamma = PhysicsCalculator.calculateGamma(xDifference, PhysicsCalculator.calculateRange(boat, target)); // gammaDegrees = PhysicsCalculator.toDegrees(gamma); // angle = PhysicsCalculator.calculateAngle(ACCELERATION, xDifference, range, gunBallVelocity); // angleAdjusted = (180 - PhysicsCalculator.toDegrees(angle)) / 2; // angle = PhysicsCalculator.toDegrees(angle) / 2; // oldVz = PhysicsCalculator.calculateGammaVelocity(gunBallVelocity, Mathf.Cos(gamma), Mathf.Sin(angleAdjusted * Mathf.PI / 180)); // oldVy = PhysicsCalculator.calculateGammaYVelocity(gunBallVelocity, angleAdjusted); // oldVx = PhysicsCalculator.calculateGammaVelocity(gunBallVelocity, Mathf.Sin(gamma), Mathf.Sin(angleAdjusted * Mathf.PI / 180)); } else { //calculate theta angle = PhysicsCalculator.calculateAngle(ACCELERATION, xDifference, range, gunBallVelocity); //change angle to degrees angle = PhysicsCalculator.toDegrees(angle) / 2; //calculate Vx oldVx = PhysicsCalculator.calculateXVelocity(gunBallVelocity, angle); //calculate Vy oldVy = PhysicsCalculator.calculateYVelocity(gunBallVelocity, angle); } //---------------- Lab #8 Additions ---------------- tau = PhysicsCalculator.calculateTau(projMass, dragCoefficient); windVelocity = 2.0f; windCoefficient = 0.1f; //---------------- Lab #9 Additions ---------------- jImpulse = PhysicsCalculator.calculateJImpulse((gunBallVelocity - targetVelocity), e, projMass, targetMass); momentumInitial.x = PhysicsCalculator.calculateMomentum(projMass, gunBallVelocity); momentumInitial.y = PhysicsCalculator.calculateMomentum(targetMass, targetVelocity); momentumInitial.z = momentumInitial.x + momentumInitial.y; }
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; } }