void OnCollisionEnter2D(Collision2D col) { if (!playerStateScript.GetIsSuffocating()) { //figure out what player/team this instance is, and check if it's colliding with the enemy team players if (col.gameObject.tag == "Player") { enemyPlayer = col.gameObject; //current player is beaverSprite // enemyInputScript = enemyPlayer.GetComponent<get_input>(); enemyStateScript = enemyPlayer.GetComponent <player_state> (); //only want players of opposite teams if (playerStateScript.GetTeamNumber() != enemyStateScript.GetTeamNumber()) { //TODO: case for both have dash on if (enemyStateScript.GetIsDashing() == true) //enemy has dash on //player becomes immobile and drops the pearl in the direction of impact { damageScript.Damage(); //knockback the other player (This player) //StartCoroutine(Knockback(beaverSprite, 1f, 350, beaverSprite.transform.position)); } } } } }
void OnCollisionEnter2D(Collision2D col) { if (!playerStateScript.GetIsSuffocating ()) { //figure out what player/team this instance is, and check if it's colliding with the enemy team players if (col.gameObject.tag == "Player") { enemyPlayer = col.gameObject; //current player is beaverSprite // enemyInputScript = enemyPlayer.GetComponent<get_input>(); enemyStateScript = enemyPlayer.GetComponent<player_state> (); //only want players of opposite teams if (playerStateScript.GetTeamNumber () != enemyStateScript.GetTeamNumber ()) { //TODO: case for both have dash on if (enemyStateScript.GetIsDashing () == true) { //enemy has dash on //player becomes immobile and drops the pearl in the direction of impact damageScript.Damage (); //knockback the other player (This player) //StartCoroutine(Knockback(beaverSprite, 1f, 350, beaverSprite.transform.position)); } } } } }
// Use this for initialization void Start() { rBody = GetComponent <Rigidbody2D>(); //get reference to the animator located on the beaver_sprite child object beaverSprite = transform.GetChild(1).gameObject; animator = beaverSprite.GetComponent <Animator>(); //reference to the beaver mouth (to determine if can breath) beaverMouth = beaverSprite.transform.GetChild(1).gameObject; moveInputScript = gameObject.GetComponent <get_input>(); playerStateScript = gameObject.GetComponent <player_state>(); facingAngle = 0.0f; facingRight = true; //facing right initially leftAnalogThresh = 0.001f; moveForce = constants.moveForceNormal; animator.SetBool("on_land", true); animator.SetBool("is_moving", false); soundPlayer = GameObject.FindGameObjectWithTag("Sound_Player").GetComponent <sound_player>(); //team 2 faces left to start if (playerStateScript.GetTeamNumber() == "2") { Flip(); } }
// Use this for initialization void Start() { rBody = GetComponent<Rigidbody2D>(); //get reference to the animator located on the beaver_sprite child object beaverSprite = transform.GetChild(1).gameObject; animator = beaverSprite.GetComponent<Animator>(); //reference to the beaver mouth (to determine if can breath) beaverMouth = beaverSprite.transform.GetChild (1).gameObject; moveInputScript = gameObject.GetComponent<get_input>(); playerStateScript = gameObject.GetComponent<player_state>(); facingAngle = 0.0f; facingRight = true; //facing right initially leftAnalogThresh = 0.001f; moveForce = constants.moveForceNormal; animator.SetBool ("on_land", true); animator.SetBool ("is_moving", false); soundPlayer = GameObject.FindGameObjectWithTag ("Sound_Player").GetComponent<sound_player>(); //team 2 faces left to start if (playerStateScript.GetTeamNumber () == "2") { Flip (); } }
// Update is called once per frame void Update() { //move the player position //for xbox controller float h = moveInputScript.GetMoveHorizontalAxis(); //mov_horiz float v = moveInputScript.GetMoveVerticalAxis(); //mov_vert //check if can breathe and set their color if (beaverMouth.transform.position.y >= constants.waterSurface) { //if transitioning to can beathe, play sound if (!playerStateScript.GetCanBreathe()) { soundPlayer.PlayClip(surfacingSound, 1.0f); } playerStateScript.SetCanBreathe(true); if ("1" == playerStateScript.GetTeamNumber()) { beaverSprite.GetComponent <SpriteRenderer>().color = constants.team1Color; } else { beaverSprite.GetComponent <SpriteRenderer>().color = constants.team2Color; } } else { //if transitioning to can't beathe, play sound if (playerStateScript.GetCanBreathe()) { soundPlayer.PlayClip(divingSound, 1.0f); } playerStateScript.SetCanBreathe(false); if ("1" == playerStateScript.GetTeamNumber()) { beaverSprite.GetComponent <SpriteRenderer>().color = constants.team1ColorWater; } else { beaverSprite.GetComponent <SpriteRenderer>().color = constants.team2ColorWater; } } if (!playerStateScript.GetIsSuffocating()) { //check if in water or at surface if (transform.position.y >= constants.waterSurface) { animator.SetBool("on_land", false); //check if walking on platform //if( transform.position.y >= platformSurface && playerStateScript.GetIsTouchingPlatform()) { if (playerStateScript.GetIsTouchingPlatform()) { rBody.gravityScale = landGravity; if (transform.position.y >= platformSurface) { animator.SetBool("on_land", true); v = 0; //do not allow vertical movement when on the platform } } else { rBody.gravityScale = airGravity; } } else { rBody.gravityScale = waterGravity; animator.SetBool("on_land", false); } } //set animation if stick is moved enough if ((Mathf.Abs(h) > leftAnalogThresh) || (Mathf.Abs(v) > leftAnalogThresh)) { //show the player moving animation animator.SetBool("is_moving", true); //move the player in the direction of the input rBody.AddForce(new Vector2(moveForce * h, 0)); rBody.AddForce(new Vector2(0, moveForce * v)); } else { animator.SetBool("is_moving", false); } // ******** // * Had to take out the following to let the dash do it's thing // *********** ////limit to max speed in x //if (rBody.velocity.x > maxSpeed) //{ // rBody.velocity = new Vector2(maxSpeed, rBody.velocity.y); //} //else if (rBody.velocity.x < maxSpeed * -1) //{ // rBody.velocity = new Vector2(maxSpeed * -1, rBody.velocity.y); //} ////limit to max speed in y //if (rBody.velocity.y > maxSpeed) //{ // rBody.velocity = new Vector2(rBody.velocity.x, maxSpeed); //} //else if (rBody.velocity.y < maxSpeed * -1) //{ // rBody.velocity = new Vector2(rBody.velocity.x, maxSpeed * -1); //} //point the beaver_sprite in the same direction as it is moving RotateBeaver(h, v); //set the offset pearl object to point in the direction it will be thrown //also sets throw angle //flip the orientation of the sprite if direction was changed if ((facingRight && h < 0) || (!facingRight && h > 0)) { Flip(); } }