/// <summary> /// Gets the horizontal displacement of the user, in the x or z directoin /// </summary> /// <param name="fwdAccel">determines if the player is acceleratig fwds</param> /// <param name="backAccel">determines if the player is accelerating backwards</param> /// <param name="displacementCalculator">which displacement calculator is being used</param> private void HorizontalDisplacement(bool fwdAccel, bool backAccel, CalculateDisplacement displacementCalculator) { //if the player is accelerating fwds and hasnt reached a max velocity of 2 if (fwdAccel && displacementCalculator.ReturnVelocity() < MAX_SPEED) { //updating the displace emnt of the user displacementCalculator.Update(SIDE_WAYS_ACCELERATION); } else if (!fwdAccel && displacementCalculator.ReturnVelocity() > NO_VALUE && !IsJumping) { //updating the displace emnt of the user displacementCalculator.Update(-SIDE_WAYS_DECCELERATION); } //if the player is acceleratting backwards and they are moving less than the max speed if (backAccel && displacementCalculator.ReturnVelocity() > -MAX_SPEED) { //updating the displace emnt of the user displacementCalculator.Update(-SIDE_WAYS_ACCELERATION); } //if the player is not accelerating backwards anfd they are still moving, they are deccelrating else if (!backAccel && displacementCalculator.ReturnVelocity() < NO_VALUE && !IsJumping) { //updating the displace emnt of the user displacementCalculator.Update(SIDE_WAYS_DECCELERATION); } }
/// <summary> /// the constructor for the bomb, and initializing all components of the bomb /// </summary> /// <param name="initialVelocity">the initial velocity of hte bomb</param> /// <param name="currentX">the players x coordinate</param> /// <param name="currentZ">the players z coordinate</param> /// <param name="currentY">the players y coordinate</param> /// <param name="playerAngle">the angle in which the player is roated at</param> /// <param name="bombImg">the bomb material that is passe don from the player class/param> public Bomb(float initialVelocity, float currentX, float currentZ, float currentY, float playerAngle, Material bombImg, GameObject explosion) { //getting the cosine and sine of the player angle float sinePlayerAngle = Mathf.Sin(playerAngle * CONVERT_TO_RAD); float cosPlayerAngle = Mathf.Cos(playerAngle * CONVERT_TO_RAD); //the starting z and x coordinates of the bomb, so that the bomb is not in the player float initialBombX = (sinePlayerAngle * DIS_FROM_PLAYER) + currentX; float initialBombZ = (cosPlayerAngle * DIS_FROM_PLAYER) + currentZ; //the timer of the bob is set to zero bombTime = NO_VALUE; //the bomb is set to active isBombActive = true; //calculating the initial horizontal and y velocities of the player initialYVelocity = (Mathf.Cos(ANGLE_OF_TRAJECTORY_RAD) * initialVelocity); horizontalVelocity = (Mathf.Sin(ANGLE_OF_TRAJECTORY_RAD) * initialVelocity); //calculating the velocity of the bomb in the z direction xVelocity = (sinePlayerAngle * horizontalVelocity); //calculating the velocity of the bomb in the z direction zVelocity = (cosPlayerAngle * horizontalVelocity); //initializing the y displacement calculator calculateY = new CalculateDisplacement(initialYVelocity); //scaling the bomb bombSphere.transform.localScale = new Vector3(BOMB_SIZE, BOMB_SIZE, BOMB_SIZE); //creating the location of the bomb suing the coordinates of the player bombSphere.transform.position = new Vector3(initialBombX, currentY + 0.4f, initialBombZ); //attaching a rigid body to the bomb bombBody = bombSphere.AddComponent <Rigidbody>(); //attaching a collider for the bomb bombCollider = bombSphere.AddComponent <SphereCollider>(); //getting the bomb sphre renderer = bombSphere.GetComponent <Renderer>(); //applying the metal material to the bomb renderer.material = bombImg; //the bomb is set to neither kinematic and does not use //pre built gravity bombBody.isKinematic = false; bombBody.useGravity = false; //initializing the explosion for th ebomb explosion1 = explosion; }
// Use this for initialization /// <summary> /// initializing all components of the players movement /// </summary> public void Start() { //initializing the diffrent displacement calculations, each one calculates displacement within a different plane //for vertical mvement calculateDisplacement[0] = new CalculateDisplacement(INITIAL_JUMP_VELOCITY); //for movement in the z direction calculateDisplacement[1] = new CalculateDisplacement(NO_VALUE); //for movement in the x direction calculateDisplacement[2] = new CalculateDisplacement(NO_VALUE); //initializing the controller controller = new Controller(); }