Example #1
0
    // Use this for initialization
    void Start()
    {
        numUpdates     = 0;
        range          = PhysicsCalculator.calculateRange(boat, target);
        moving         = true;
        gunBallSpawned = false;
        initial        = true;
        lastMarker     = numUpdates;
        buffer         = 3;
        fixedTime      = Time.fixedDeltaTime;

        //calculate theta
        angle = PhysicsCalculator.calculateTheta(range, gunBallVelocity);

        //calculate the total time
        totalTime = PhysicsCalculator.calculateProjTime(range, gunBallVelocity, angle);

        //change angle to degrees
        angle          = angle * 180 / Mathf.PI;
        angleText.text = "Angle: " + angle + " degrees";

        //calculate Vx
        oldVx = PhysicsCalculator.calculateXVelocity(gunBallVelocity, angle);
        //calculate Vy
        oldVy = PhysicsCalculator.calculateYVelocity(gunBallVelocity, angle);
    }
Example #2
0
    // 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;
    }
Example #3
0
    // Use this for initialization
    void Start()
    {
        numUpdates     = 0;
        range          = PhysicsCalculator.calculateRange(boat, target);
        moving         = true;
        gunBallSpawned = false;
        initial        = true;
        lastMarker     = numUpdates;
        buffer         = 3;
        fixedTime      = Time.fixedDeltaTime;
        xDifference    = PhysicsCalculator.calculateXDifference(boat, target);

        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.calculateTheta(range, gunBallVelocity);

            //change angle to degrees
            angle = angle * 180 / Mathf.PI;

            //calculate Vx
            oldVx = PhysicsCalculator.calculateXVelocity(gunBallVelocity, angle);
            //calculate Vy
            oldVy = PhysicsCalculator.calculateYVelocity(gunBallVelocity, angle);
        }
    }