Ejemplo n.º 1
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateMH
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the MH values for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateMH()
    {
        mh_boat   = PhysicsCalculator.calculateMH(h_boat, mass_boat);
        mh_pilot  = PhysicsCalculator.calculateMH(h_pilot, mass_pilot);
        mh_cannon = PhysicsCalculator.calculateMH(h_cannon, mass_cannon);
        mh_com    = PhysicsCalculator.calculateCombined(mh_boat, mh_pilot, mh_cannon);
    }
Ejemplo n.º 2
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateMH
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the moment of inertia for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateMomentOfInertia()
    {
        moi_boat   = PhysicsCalculator.calculateMOI(boat.getMass(), boat.getXDim(), boat.getZDim());
        moi_pilot  = PhysicsCalculator.calculateMOI(pilot.getMass(), pilot.getXDim(), pilot.getZDim());
        moi_cannon = PhysicsCalculator.calculateMOI(cannon.getMass(), cannon.getXDim(), cannon.getZDim());
        moi_com    = PhysicsCalculator.calculateCombined(moi_boat, moi_pilot, moi_cannon);
    }
Ejemplo n.º 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;

        //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);
    }
Ejemplo n.º 4
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateInertiaTotals
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the inertia totals for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateInertiaTotals()
    {
        it_boat   = PhysicsCalculator.calculateInertiaTotal(moi_boat, mh_boat);
        it_pilot  = PhysicsCalculator.calculateInertiaTotal(moi_pilot, mh_pilot);
        it_cannon = PhysicsCalculator.calculateInertiaTotal(moi_cannon, mh_cannon);
        it_com    = PhysicsCalculator.calculateCombined(it_boat, it_pilot, it_cannon);
    }
Ejemplo n.º 5
0
    public void CollisionCalibration()
    {
        Vector3    totalNormalForce = Vector3.zero;
        int        noOfCycles       = 0;
        RaycastHit hit = rayCaster.GetCollisionData(velocity, 0);

        do
        {
            //Add one cycle
            noOfCycles++;

            //Make adjustments to normalforce
            Vector3 normalForce = MeasureNormalForce();
            velocity         += normalForce;
            totalNormalForce += normalForce;

            //Look for new collisions
            hit = rayCaster.GetCollisionData(velocity, 0);
        }while (hit.collider != null && noOfCycles < 1000);

        velocity = PhysicsCalculator.CalculateFriction(velocity, totalNormalForce, staticFrictionCo);

        if (hit.collider == null)
        {
            transform.position += velocity * Time.deltaTime;
        }
    }
Ejemplo n.º 6
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateComValues
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the center of mass the whole object and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateComValues()
    {
        comX = PhysicsCalculator.calculateComX(mass_boat, boat.getX(), mass_pilot, pilot.getX(), mass_cannon, cannon.getX(), mass_com);
        comZ = PhysicsCalculator.calculateComZ(mass_boat, boat.getZ(), mass_pilot, pilot.getZ(), mass_cannon, cannon.getZ(), mass_com);

        comFloats[4] = comX;
        comFloats[5] = comZ;
    }
Ejemplo n.º 7
0
    public Vector3 MeasureNormalForce()
    {
        Vector3    normalForce = Vector3.zero;
        RaycastHit hit         = rayCaster.GetCollisionData(velocity, 0);

        normalForce = PhysicsCalculator.CalculateNormalForce(velocity, hit);
        return(normalForce);
    }
Ejemplo n.º 8
0
    // Use this for initialization
    private void Start()
    {
        _rigidBody = GetComponent <Rigidbody>();
        var coefficientofFriction = GetComponent <Collider>().material.dynamicFriction;



        var forceApplied = PhysicsCalculator.CalculateFlatForceRequired()
    }
Ejemplo n.º 9
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;
    }
Ejemplo n.º 10
0
    void FixedUpdate()
    {
        if (moving && gunBallSpawned)
        {
            if (initial)
            {
                initial = false;
                timeBeg = Time.time;
                //rotates the cannon by the calculated angle
                boat.transform.rotation = Quaternion.Euler(-angle, 0, 0);
            }

            angle = PhysicsCalculator.calculateTheta(range, gunBallVelocity) * 180 / Mathf.PI;

            newVx = PhysicsCalculator.calculateVelocity(oldVx, 0, fixedTime);
            newVy = PhysicsCalculator.calculateVelocity(oldVy, ACCELERATION, fixedTime);

            //update positions accordingly
            newDx = PhysicsCalculator.calculateDistance(currentDx, 0, newVx, fixedTime);
            newDy = PhysicsCalculator.calculateDistance(currentDy, ACCELERATION, newVy, fixedTime);

            if (gunball.transform.position.y - target.transform.position.y <= 0.05 && numUpdates > 0)
            {
                moving        = false;
                timeText.text = "Time: " + totalTime + " seconds";
            }
            else
            {
                yDisplacement = newVy * fixedTime;
                zDisplacement = newVx * fixedTime;
                gunball.transform.position = new Vector3(gunball.transform.position.x, gunball.transform.position.y + yDisplacement, gunball.transform.position.z + zDisplacement);

                if (lastMarker + buffer < numUpdates)
                {
                    lastMarker = numUpdates;
                    Object.Instantiate(flightMarker, new Vector3(gunball.transform.position.x, gunball.transform.position.y + yDisplacement, gunball.transform.position.z + zDisplacement), Quaternion.identity);
                }
            }
        }

        if (moving && gunBallSpawned)
        {
            //update UI
            initialVelText.text = "Init. Velocity: " + gunBallVelocity + " m/s";
            rangeText.text      = "Range: " + range + " m";
            timeText.text       = "Time: " + (Time.time - timeBeg) + " seconds";
            updatesText.text    = "Updates: " + (numUpdates + 1) + " frames";
            gunBallText.text    = "Gunball Z: " + gunball.transform.position.z + " m";

            numUpdates++;
            oldVx     = newVx;
            oldVy     = newVy;
            currentDx = newDx;
            currentDy = newDy;
        }
    }
Ejemplo n.º 11
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateH
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the H values for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateH()
    {
        h_boat   = PhysicsCalculator.calculateRotationPoint(boat.getX(), boat.getZ(), comX, comZ);
        h_pilot  = PhysicsCalculator.calculateRotationPoint(pilot.getX(), pilot.getZ(), comX, comZ);
        h_cannon = PhysicsCalculator.calculateRotationPoint(cannon.getX(), cannon.getZ(), comX, comZ);

        boatFloats[2]   = h_boat;
        pilotFloats[2]  = h_pilot;
        cannonFloats[2] = h_cannon;
    }
Ejemplo n.º 12
0
    public void AddForces()
    {
        //Calculate velocity, add gravity
        Vector3 gravity = PhysicsCalculator.CalculateGravity(gravitationalForce);

        velocity  = PhysicsCalculator.ApplyAcceleration(velocity, direction, acceleration);
        velocity += gravity;

        //Add Air resistance
        velocity = PhysicsCalculator.AddAirResistance(velocity, airResistance);
    }
Ejemplo n.º 13
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateInertiaTotals
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the inertia totals for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateInertiaTotals()
    {
        it_boat   = PhysicsCalculator.calculateInertiaTotal(moi_boat, mh_boat);
        it_pilot  = PhysicsCalculator.calculateInertiaTotal(moi_pilot, mh_pilot);
        it_cannon = PhysicsCalculator.calculateInertiaTotal(moi_cannon, mh_cannon);
        it_com    = PhysicsCalculator.calculateCombined(it_boat, it_pilot, it_cannon);

        boatFloats[8]   = it_boat;
        pilotFloats[8]  = it_pilot;
        cannonFloats[8] = it_cannon;
        comFloats[8]    = it_com;
    }
Ejemplo n.º 14
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateMH
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the MH values for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateMH()
    {
        mh_boat   = PhysicsCalculator.calculateMH(h_boat, mass_boat);
        mh_pilot  = PhysicsCalculator.calculateMH(h_pilot, mass_pilot);
        mh_cannon = PhysicsCalculator.calculateMH(h_cannon, mass_cannon);
        mh_com    = PhysicsCalculator.calculateCombined(mh_boat, mh_pilot, mh_cannon);

        boatFloats[3]   = mh_boat;
        pilotFloats[3]  = mh_pilot;
        cannonFloats[3] = mh_cannon;
        comFloats[3]    = mh_com;
    }
Ejemplo n.º 15
0
    public void pause()
    {
        moving = !moving;

        //react to the collision
        oldVx = PhysicsCalculator.calculateRecoilVelocity(jImpulse, projMass, gunBallVelocity);
        gunBallVelocityFinal = oldVx;

        targetVelocity = PhysicsCalculator.calculateRecoilVelocity(-jImpulse, targetMass, targetVelocity);

        momentumFinal.x = PhysicsCalculator.calculateMomentum(projMass, oldVx);
        momentumFinal.y = PhysicsCalculator.calculateMomentum(targetMass, targetVelocity);
        momentumFinal.z = momentumFinal.x + momentumFinal.y;
    }
Ejemplo n.º 16
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: Start
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Initializes the various objects to call member functions.
 * -- Initializes the canvas controller to update the HUD.
 * -- Initializes the data arrays.
 * ----------------------------------------------------------------------------------------------------------------------*/
    void Start()
    {
        //------- LAB #6 Additions -------
        moving     = false;
        initial    = true;
        numUpdates = 0;
        fixedTime  = Time.fixedDeltaTime;

        //calculate different acceleration directions
        thrust.x = PhysicsCalculator.calculateXThrust(force, angle);
        thrust.z = PhysicsCalculator.calculateZThrust(force, angle);

        thrustAngle.x = PhysicsCalculator.calculateXThrust(angularForce, angle);
        thrustAngle.z = PhysicsCalculator.calculateZThrust(angularForce, angle);
    }
Ejemplo n.º 17
0
    // Use this for initialization
    void Start()
    {
        numUpdates = 0;

        currentD = 0;
        oldV     = velocity;
        moving   = true;

        if (useDrag)
        {
            dragConstant = PhysicsCalculator.calculateDragConstant(acceleration, velocity);
        }

        distance = PhysicsCalculator.calculateDistance(0, acceleration, velocity, time);
        dt       = PhysicsCalculator.calculateDragTime(dragConstant, distance, velocity);
    }
Ejemplo n.º 18
0
    void Start()
    {
        numUpdates = 0;

        moving         = false;
        gunBallSpawned = false;
        initial        = true;
        collided       = false;

        lastMarker = numUpdates;
        buffer     = 3;
        fixedTime  = Time.fixedDeltaTime;

        //---------------- Lab #11 Additions ----------------
        moi1 = PhysicsCalculator.calculateMOI(projMass);
        moi2 = PhysicsCalculator.calculateMOI(targetMass);
    }
Ejemplo n.º 19
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++;
        }
    }
Ejemplo n.º 20
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;
        }
    }
Ejemplo n.º 21
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);
        }
    }
Ejemplo n.º 22
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: Update
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls helper functions that calculate various attributes.
 * -- Calls helper functions to load data arrays used to display the various attributes to the user.
 * -- Updates the COM Point material to move the com point shader around.
 * ----------------------------------------------------------------------------------------------------------------------*/
    void Update()
    {
        mass_boat   = boat.getMass();
        mass_pilot  = pilot.getMass();
        mass_cannon = cannon.getMass();
        mass_com    = PhysicsCalculator.calculateCombined(mass_boat, mass_pilot, mass_cannon);

        boatFloats[0]   = mass_boat;
        pilotFloats[0]  = mass_pilot;
        cannonFloats[0] = mass_cannon;
        comFloats[0]    = mass_com;

        loadBoatFloats();
        loadPilotFloats();
        loadCannonFloats();

        calculateMomentOfInertia();
        calculateComValues();
        calculateH();
        calculateMH();
        calculateInertiaTotals();

        comPoint.SetVector("_COMPosition", new Vector3(comX, 0, comZ));
    }
Ejemplo n.º 23
0
    void FixedUpdate()
    {
        if (moving && gunBallSpawned)
        {
            if (initial)
            {
                initial = false;

                if (xDifference == 0)
                {
                    //rotates the cannon by the calculated angle
                    boat.transform.rotation = Quaternion.Euler(-angle, 0, 0);
                }
                else
                {
                    //gamma/alpha rotation of the cannon
                    boat.transform.rotation = Quaternion.Euler(-angle, PhysicsCalculator.toDegrees(gamma), 0);
                }
            }

            angle = PhysicsCalculator.calculateTheta(range, gunBallVelocity) * 180 / Mathf.PI;

            //run lab 4
            // newVx = PhysicsCalculator.calculateVelocity(oldVx, 0, fixedTime);
            // newVy = PhysicsCalculator.calculateYVelocityGamma(oldVy, -ACCELERATION, fixedTime);
            newVz = PhysicsCalculator.calculateVelocity(oldVz, 0, fixedTime);

            // newDx = PhysicsCalculator.calculateXPosition(currentDx, oldVx, angle, gamma, fixedTime);
            // newDy = PhysicsCalculator.calculateYPosition(currentDy, oldVy, -ACCELERATION, fixedTime);
            // newDz = PhysicsCalculator.calculateZPosition(oldDz, oldVz, angle, PhysicsCalculator.toDegrees(gamma), fixedTime);

            if (Mathf.Abs(gunball.transform.position.z - target.transform.position.z) < 1 && numUpdates > 0 && !collided)
            {
                pause();
                timeText.text = "Time: " + ((numUpdates + 1) * fixedTime) + " seconds";
            }
            else
            {
                if (xDifference == 0)
                {
                    gunball.transform.Translate(gunball.transform.position.x, gunball.transform.position.y, newVx * fixedTime);
                }
                else
                {
                    // //handles any quadrant case
                    // if (target.transform.position.x < boat.transform.position.x && target.transform.position.z < boat.transform.position.z) {
                    //  gunball.transform.Translate(-newVx * fixedTime, newVy * fixedTime, -newVz * fixedTime);
                    // } else if (target.transform.position.x < boat.transform.position.x) {
                    //  gunball.transform.Translate(-newVx * fixedTime, newVy * fixedTime, newVz * fixedTime);
                    // } else if (target.transform.position.z < boat.transform.position.z) {
                    //  gunball.transform.Translate(newVx * fixedTime, newVy * fixedTime, -newVz * fixedTime);
                    // } else {
                    //  gunball.transform.Translate(newVx * fixedTime, newVy * fixedTime, newVz * fixedTime);
                    // }

                    if (!collided)
                    {
                        gunball.transform.Translate(gunball.transform.position.x, gunball.transform.position.y, gunBallVelocity * fixedTime);
                        target.transform.Translate(0, 0, targetVelocity * fixedTime);
                    }
                    else
                    {
                        gunball.transform.Translate(bulletXFinal * fixedTime, gunball.transform.position.y, bulletZfinal * fixedTime);
                        target.transform.Translate(targetXFinal * fixedTime, target.transform.position.y, targetZfinal * fixedTime);
                    }
                }

                if (lastMarker + buffer < numUpdates)
                {
                    lastMarker = numUpdates;
                    Object.Instantiate(flightMarker, new Vector3(gunball.transform.position.x, gunball.transform.position.y + yDisplacement, gunball.transform.position.z + zDisplacement), Quaternion.identity);
                }
            }
        }

        if (moving && gunBallSpawned)
        {
            numUpdates++;

            //update UI
            posText.text     = "Masses (Ball/Target): " + projMass + "kg, " + targetMass + "kg";
            timeText.text    = "Time: " + ((numUpdates + 1) * fixedTime) + " seconds";
            updatesText.text = "Updates: " + (numUpdates + 1) + " frames";

            oldVx = newVx;
            oldVz = newVz;

            currentDx = newDx;
            currentDy = newDy;
            oldDz     = newDz;
        }
    }
Ejemplo n.º 24
0
    public void pause()
    {
        moving   = !moving;
        collided = true;

        R1.x = gunball.transform.position.x;
        R1.y = gunball.transform.position.y;
        R1.z = gunball.transform.position.z;

        R2.x = target.transform.position.x;
        R2.y = target.transform.position.y;
        R2.z = target.transform.position.z;

        P.z = target.transform.position.z - 0.5f;
        P.x = gunball.transform.position.x + (target.transform.position.x - gunball.transform.position.x) / 2;

        //reposition the cube
        gunball.transform.position = new Vector3(gunball.transform.position.x, gunball.transform.position.y, target.transform.position.z - 1);

        //Lab #10
        normals.x = target.transform.position.x - gunball.transform.position.x;
        normals.z = target.transform.position.z - gunball.transform.position.z;

        //lab #11 additions
        lowCaseR1 = PhysicsCalculator.calculateSubtractVector(P, gunball.transform.position);
        lowCaseR2 = PhysicsCalculator.calculateSubtractVector(P, target.transform.position);

        //hacky fix :)
        normals.x     = 0;
        tangentials.z = normals.x;
        //--------------------------------

        jImpulse = PhysicsCalculator.calculateJImpulse((gunBallVelocity - targetVelocity), e, projMass, targetMass, normals, lowCaseR1, lowCaseR2, moi1, moi2);

        omegaBallF   = -(omegaBallI + Vector3.Cross(lowCaseR1, (normals * jImpulse)) / moi1);
        omegaTargetF = omegaTargetI + Vector3.Cross(lowCaseR2, (normals * jImpulse)) / moi2;

        //Lab #10
        jNormal = (jImpulse * normals.z) + (0 * normals.x);

        //react to the collision
        gunBallVelocityFinal = PhysicsCalculator.calculateRecoilVelocity(jNormal, projMass, gunBallVelocity);
        targetVelocityFinal  = PhysicsCalculator.calculateRecoilVelocity(-jNormal, targetMass, targetVelocity);

        tangentials.z = normals.x * -1;
        tangentials.x = normals.z;

        bulletinitialNormal = (gunBallVelocity * normals.z) + (0 * normals.x);
        bulletinitialTang   = (gunBallVelocity * tangentials.z) + (0 * tangentials.x);

        targetinitialNormal = (targetVelocity * normals.z) + (0 * normals.x);
        targetinitialTang   = (targetVelocity * tangentials.z) + (0 * tangentials.z);

        //final normals
        bulletZfinalNormal = (jNormal / projMass + bulletinitialNormal) * normals.z;
        bulletZfinalTang   = (bulletinitialTang * tangentials.z);

        targetZfinalNormal = ((-jNormal) / targetMass + targetinitialNormal) * normals.z;
        targetZfinalTang   = (targetinitialTang * tangentials.z);

        //z velocities
        bulletZfinal = bulletZfinalNormal + bulletZfinalTang;
        targetZfinal = targetZfinalNormal + targetZfinalTang;

        bulletXfinalNormal = (jNormal / projMass + bulletinitialNormal) * normals.x;
        bulletXfinalTang   = (bulletinitialTang * tangentials.x);

        targetXfinalNormal = ((-jNormal) / targetMass + targetinitialNormal) * normals.x;
        targetXfinalTang   = targetinitialTang * tangentials.x;

        //x velocities
        bulletXFinal = bulletXfinalNormal + bulletXfinalTang;
        targetXFinal = targetXfinalNormal + targetXfinalTang;

        //bullet, target, final
        //momentum
        momentumInitialZ.x = projMass * gunBallVelocity;
        momentumInitialZ.y = targetMass * targetVelocity;
        momentumInitialZ.z = momentumInitialZ.x + momentumInitialZ.y;

        momentumFinalZ.x = projMass * bulletZfinal;
        momentumFinalZ.y = targetMass * targetZfinal;
        momentumFinalZ.z = momentumFinalZ.x + momentumFinalZ.y;

        momentumInitialX.x = 0f;
        momentumInitialX.y = 0f;
        momentumInitialX.z = momentumInitialX.x + momentumInitialX.y;

        momentumFinalX.x = projMass * bulletXFinal;
        momentumFinalX.y = targetMass * targetXFinal;
        momentumFinalX.z = momentumFinalX.x + momentumFinalX.y;

        //energy
        energyInitialZ.x = 0.5f * projMass * gunBallVelocity * gunBallVelocity;
        energyInitialZ.y = 0.5f * targetMass * targetVelocity * targetVelocity;
        energyInitialZ.z = energyInitialZ.x + energyInitialZ.y;

        energyFinalZ.x = 0.5f * projMass * bulletZfinal * bulletZfinal;
        energyFinalZ.y = 0.5f * targetMass * targetZfinal * targetZfinal;
        energyFinalZ.z = energyFinalZ.x + energyFinalZ.y;

        energyInitialX.x = 0.5f * projMass * 0.0f * 0.0f;
        energyInitialX.y = 0.5f * targetMass * 0.0f * 0.0f;
        energyInitialX.z = energyInitialX.x + energyInitialX.y;

        energyFinalX.x = 0.5f * projMass * bulletXFinal * bulletXFinal;
        energyFinalX.y = 0.5f * targetMass * targetXFinal * targetXFinal;
        energyFinalX.z = energyFinalX.x + energyFinalX.y;

        //rotational energy
        rotEnergy.x = (0.5f * moi1 * omegaBallF.y * omegaBallF.y);
        rotEnergy.y = (0.5f * moi2 * omegaTargetF.y * omegaTargetF.y);
        rotEnergy.z = rotEnergy.x + rotEnergy.y;

        totalEnergy = energyFinalZ.z + (0.5f * moi1 * omegaBallF.y * omegaBallF.y) + (0.5f * moi2 * omegaTargetF.y * omegaTargetF.y);

        //gunball momentum values
        Vector3 gunballInitialMomentum = new Vector3(momentumInitialX.x, 0.0f, momentumInitialZ.x);
        //nothing happening in x, hence why it's 0
        Vector3 gunballFinalMomentum = new Vector3(0.0f, 0.0f, momentumFinalZ.x);

        //target momentum values
        Vector3 targetInitialMomentum = new Vector3(momentumInitialX.y, 0.0f, momentumInitialZ.y);
        //nothing happening in x, hence why it's 0
        Vector3 targetFinalMomentum = new Vector3(0.0f, 0.0f, momentumFinalZ.y);

        LInitial = PhysicsCalculator.calculateAngularMomentum(lowCaseR1, lowCaseR2, gunballInitialMomentum, targetInitialMomentum);

        LFinal1 = Vector3.Cross(lowCaseR1, gunballFinalMomentum) + (moi1 * omegaBallF);
        LFinal2 = Vector3.Cross(lowCaseR2, targetFinalMomentum) + (moi2 * omegaTargetF);

        LFinalTotal = LFinal1 + LFinal2;
    }
Ejemplo n.º 25
0
    void FixedUpdate()
    {
        if (moving && gunBallSpawned)
        {
            if (initial)
            {
                initial = false;

                if (xDifference == 0)
                {
                    //rotates the cannon by the calculated angle
                    boat.transform.rotation = Quaternion.Euler(-angle, 0, 0);
                }
                else
                {
                    //gamma/alpha rotation of the cannon
                    boat.transform.rotation = Quaternion.Euler(-angle, PhysicsCalculator.toDegrees(gamma), 0);
                }
            }

            angle = PhysicsCalculator.calculateTheta(range, gunBallVelocity) * 180 / Mathf.PI;

            newVx = PhysicsCalculator.calculateXVelocityWithWind(fixedTime, tau, oldVx, windCoefficient, windVelocity, gamma, dragCoefficient);
            newVy = PhysicsCalculator.calculateYVelocityWithWind(dragCoefficient, fixedTime, projMass, oldVy);
            newVz = PhysicsCalculator.calculateZVelocityWithWind(fixedTime, tau, oldVz, windCoefficient, windVelocity, gamma, dragCoefficient);

            newDx = PhysicsCalculator.calculateXPositionWithWind(currentDx, oldVx, tau, fixedTime, windCoefficient, windVelocity, dragCoefficient, gamma);
            newDy = PhysicsCalculator.calculateYPositionWithWind(currentDy, oldVy, tau, fixedTime);
            newDz = PhysicsCalculator.calculateZPositionWithWind(oldDz, oldVz, tau, fixedTime, windVelocity, gamma, windCoefficient, dragCoefficient);

            if (gunball.transform.position.y <= 0.05 && numUpdates > 0)
            {
                moving        = false;
                timeText.text = "Time: " + ((numUpdates + 1) * fixedTime) + " seconds";
            }
            else
            {
                if (xDifference == 0)
                {
                    if (target.transform.position.z > boat.transform.position.z)
                    {
                        gunball.transform.Translate(gunball.transform.position.x, newVy * fixedTime, newVx * fixedTime);
                    }
                    else
                    {
                        gunball.transform.Translate(gunball.transform.position.x, newVy * fixedTime, -newVx * fixedTime);
                    }
                }
                else
                {
                    //handles any quadrant case
                    if (target.transform.position.x < boat.transform.position.x && target.transform.position.z < boat.transform.position.z)
                    {
                        gunball.transform.Translate(-newVx * fixedTime, newVy * fixedTime, -newVz * fixedTime);
                    }
                    else if (target.transform.position.x < boat.transform.position.x)
                    {
                        gunball.transform.Translate(-newVx * fixedTime, newVy * fixedTime, newVz * fixedTime);
                    }
                    else if (target.transform.position.z < boat.transform.position.z)
                    {
                        gunball.transform.Translate(newVx * fixedTime, newVy * fixedTime, -newVz * fixedTime);
                    }
                    else
                    {
                        gunball.transform.Translate(newVx * fixedTime, newVy * fixedTime, newVz * fixedTime);
                    }
                }

                if (lastMarker + buffer < numUpdates)
                {
                    lastMarker = numUpdates;
                    Object.Instantiate(flightMarker, new Vector3(gunball.transform.position.x, gunball.transform.position.y + yDisplacement, gunball.transform.position.z + zDisplacement), Quaternion.identity);
                }
            }
        }

        if (moving && gunBallSpawned)
        {
            numUpdates++;

            //update UI
            posText.text     = "Position: " + gunball.transform.position.x + ", " + gunball.transform.position.y + ", " + gunball.transform.position.z;
            timeText.text    = "Time: " + ((numUpdates + 1) * fixedTime) + " seconds";
            updatesText.text = "Updates: " + (numUpdates + 1) + " frames";

            oldVx = newVx;
            oldVy = newVy;
            oldVz = newVz;

            currentDx = newDx;
            currentDy = newDy;
            oldDz     = newDz;
        }
    }
Ejemplo n.º 26
0
    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;
        }
    }
Ejemplo n.º 27
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: Update
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls helper functions that calculate various attributes.
 * -- Calls helper functions to load data arrays used to display the various attributes to the user.
 * -- Updates the COM Point material to move the com point shader around.
 * ----------------------------------------------------------------------------------------------------------------------*/
    void Update()
    {
        //------- LAB #6 Additions -------
        // acceleration = PhysicsCalculator.calculateAccelerationFromThrust(force, mass_com);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            moving = !moving;
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            force  = 30000;
            moving = true;
        }

        if (Input.GetKeyUp(KeyCode.W) && dynamicControls)
        {
            force = 0;
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            rotLeft  = true;
            rotRight = false;
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            rotRight = true;
            rotLeft  = false;
        }

        if (initial)
        {
            //------- LAB #1 Originals -------
            pilot  = p.GetComponent <Pilot>();
            boat   = b.GetComponent <Boat>();
            cannon = c.GetComponent <Cannon>();

            mass_boat   = boat.getMass();
            mass_pilot  = pilot.getMass();
            mass_cannon = cannon.getMass();
            mass_com    = PhysicsCalculator.calculateCombined(mass_boat, mass_pilot, mass_cannon);

            calculateMomentOfInertia();
            calculateComValues();
            calculateH();
            calculateMH();
            calculateInertiaTotals();

            comPoint.SetVector("_COMPosition", new Vector3(comX, 0, comZ));

            //------- LAB #6 Additions -------
            acceleration.x = PhysicsCalculator.calculateAccelerationFromThrust(thrust.x, mass_com);
            acceleration.z = PhysicsCalculator.calculateAccelerationFromThrust(thrust.z, mass_com);

            rLeft.x = 2 - comX;
            rLeft.y = 0;
            rLeft.z = -4 - comZ;

            rRight.x = -2 - comX;
            rRight.y = 0;
            rRight.z = -4 - comZ;

            torqueL = PhysicsCalculator.calculateCrossProd(new Vector3(thrustAngle.x, 0, thrustAngle.z), rLeft);
            torqueR = PhysicsCalculator.calculateCrossProd(new Vector3(thrustAngle.x, 0, thrustAngle.z), rRight);

            accelerationL = PhysicsCalculator.calculateAngularAcceleration(torqueL.y, it_com);
            accelerationR = PhysicsCalculator.calculateAngularAcceleration(torqueR.y, it_com);

            initial = false;
        }
    }
Ejemplo n.º 28
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: Update
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls helper functions that calculate various attributes.
 * -- Calls helper functions to load data arrays used to display the various attributes to the user.
 * -- Updates the COM Point material to move the com point shader around.
 * ----------------------------------------------------------------------------------------------------------------------*/
    void Update()
    {
        //Pause/unpause simulation
        if (Input.GetKeyDown(KeyCode.Space))
        {
            moving = !moving;
        }

        //Forward Thrust
        if (Input.GetKeyDown(KeyCode.W))
        {
            force = 4000;
        }

        //Release forward thrust
        if (Input.GetKeyUp(KeyCode.W))
        {
            force = 0;
        }

        //Left torque
        if (Input.GetKeyDown(KeyCode.Q))
        {
            rotLeft  = true;
            rotRight = false;

            turnForce = -1000;
        }

        //Right torque
        if (Input.GetKeyDown(KeyCode.E))
        {
            rotRight = true;
            rotLeft  = false;

            turnForce = 1000;
        }

        //Release directional torque
        if (Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.Q))
        {
            rotRight = false;
            rotLeft  = false;

            turnForce = 0;
        }

        if (initial)
        {
            //Initialize objects to access attributes
            pilot  = p.GetComponent <Pilot>();
            boat   = b.GetComponent <Boat>();
            cannon = c.GetComponent <Cannon>();

            mass_boat   = boat.getMass();
            mass_pilot  = pilot.getMass();
            mass_cannon = cannon.getMass();
            mass_com    = PhysicsCalculator.calculateCombined(mass_boat, mass_pilot, mass_cannon);

            calculateMomentOfInertia();
            calculateComValues();
            calculateH();
            calculateMH();
            calculateInertiaTotals();

            comPoint.SetVector("_COMPosition", new Vector3(comX, 0, comZ));
            initial = false;
        }
    }
Ejemplo n.º 29
0
 public void Jump()
 {
     {
         velocity = PhysicsCalculator.CalculateJump(velocity, JumpMagnitude);
     }
 }
Ejemplo n.º 30
0
    public void pause()
    {
        moving   = !moving;
        collided = true;

        float x = Mathf.Abs(gunball.transform.position.x - target.transform.position.x);
        float z = Mathf.Sqrt(1 - Mathf.Pow(x, 2));

        gunball.transform.position = new Vector3(gunball.transform.position.x, gunball.transform.position.y, target.transform.position.z - z);

        //react to the collision
        gunBallVelocityFinal = PhysicsCalculator.calculateRecoilVelocity(jImpulse, projMass, gunBallVelocity);
        targetVelocityFinal  = PhysicsCalculator.calculateRecoilVelocity(-jImpulse, targetMass, targetVelocity);

        //Lab #10
        normals.x = target.transform.position.x - gunball.transform.position.x;
        normals.z = target.transform.position.z - gunball.transform.position.z;

        jNormal = (jImpulse * normals.z) + (0 * normals.x);

        tangentials.z = normals.x * -1;
        tangentials.x = normals.z;

        bulletinitialNormal = (gunBallVelocity * normals.z) + (0 * normals.x);
        bulletinitialTang   = (gunBallVelocity * tangentials.z) + (0 * tangentials.x);

        targetinitialNormal = (targetVelocity * normals.z) + (0 * normals.x);
        targetinitialTang   = (targetVelocity * tangentials.z) + (0 * tangentials.z);

        bulletZfinalNormal = (jNormal / projMass + bulletinitialNormal) * normals.z;
        bulletZfinalTang   = (bulletinitialTang * tangentials.z);

        targetZfinalNormal = ((-jNormal) / targetMass + targetinitialNormal) * normals.z;
        targetZfinalTang   = (targetinitialTang * tangentials.z);

        //z velocities
        bulletZfinal = bulletZfinalNormal + bulletZfinalTang;
        targetZfinal = targetZfinalNormal + targetZfinalTang;

        bulletXfinalNormal = (jNormal / projMass + bulletinitialNormal) * normals.x;
        bulletXfinalTang   = (bulletinitialTang * tangentials.x);

        targetXfinalNormal = ((-jNormal) / targetMass + targetinitialNormal) * normals.x;
        targetXfinalTang   = targetinitialTang * tangentials.x;

        //x velocities
        bulletXFinal = bulletXfinalNormal + bulletXfinalTang;
        targetXFinal = targetXfinalNormal + targetXfinalTang;

        //bullet, target, final
        //momentum
        momentumInitialZ.x = projMass * gunBallVelocity;
        momentumInitialZ.y = targetMass * targetVelocity;
        momentumInitialZ.z = momentumInitialZ.x + momentumInitialZ.y;

        momentumFinalZ.x = projMass * bulletZfinal;
        momentumFinalZ.y = targetMass * targetZfinal;
        momentumFinalZ.z = momentumFinalZ.x + momentumFinalZ.y;

        momentumInitialX.x = 0f;
        momentumInitialX.y = 0f;
        momentumInitialX.z = momentumInitialX.x + momentumInitialX.y;

        momentumFinalX.x = projMass * bulletXFinal;
        momentumFinalX.y = targetMass * targetXFinal;
        momentumFinalX.z = momentumFinalX.x + momentumFinalX.y;

        //energy
        energyInitialZ.x = 0.5f * projMass * gunBallVelocity * gunBallVelocity;
        energyInitialZ.y = 0.5f * targetMass * targetVelocity * targetVelocity;
        energyInitialZ.z = energyInitialZ.x + energyInitialZ.y;

        energyFinalZ.x = 0.5f * projMass * bulletZfinal * bulletZfinal;
        energyFinalZ.y = 0.5f * targetMass * targetZfinal * targetZfinal;
        energyFinalZ.z = energyFinalZ.x + energyFinalZ.y;

        energyInitialX.x = 0.5f * projMass * 0.0f * 0.0f;
        energyInitialX.y = 0.5f * targetMass * 0.0f * 0.0f;
        energyInitialX.z = energyInitialX.x + energyInitialX.y;

        energyFinalX.x = 0.5f * projMass * bulletXFinal * bulletXFinal;
        energyFinalX.y = 0.5f * targetMass * targetXFinal * targetXFinal;
        energyFinalX.z = energyFinalX.x + energyFinalX.y;

        totalEnergy = energyFinalX.z + energyFinalZ.z;
    }