// Use this for initialization void Start() { mRB = GetComponent <Rigidbody2D>(); gm = GameObject.Find("Game Manager"); gb = gm.GetComponent <GlobalBehavior>(); rayCastLeft = GameObject.Find("ray_cast_left").GetComponent <raycastUp>(); rayCastRight = GameObject.Find("ray_cast_right").GetComponent <raycastUp>(); speedMultiplier = 1; gb.UpdateLandingText("Landing: In Air"); gb.UpdateTrickText("Trick: "); }
void OnTriggerEnter2D(Collider2D other) { #region ground trigger if (other.gameObject.CompareTag("GroundCollider") && jumped) { float angle = Vector2.Angle(this.transform.right, rayCastRight.point - rayCastLeft.point); Debug.Log(angle); if (angle <= 15f) { int reward = 20; jumped = false; speedMultiplier = 2f; boost = true; gb.UpdateLandingText("Landing: Perfect! +" + reward.ToString()); gb.UpdateScore(reward); } else if (angle <= 30f) { int reward = 15; speedMultiplier = 1.8f; boost = true; jumped = false; gb.UpdateLandingText("Landing: Great! +" + reward.ToString()); gb.UpdateScore(reward); } else if (angle <= 45f) { int reward = 10; speedMultiplier = 1.6f; boost = true; jumped = false; gb.UpdateLandingText("Landing: Good! +" + reward.ToString()); gb.UpdateScore(reward); } else if (angle <= 60f) { int reward = 5; speedMultiplier = 1.2f; boost = true; jumped = false; gb.UpdateLandingText("Landing: Alright +" + reward.ToString()); gb.UpdateScore(reward); } else if (angle <= 90f) { int reward = 2; speedMultiplier = 0.5f; boost = true; jumped = false; gb.UpdateLandingText("Landing: Poor +" + reward.ToString()); gb.UpdateScore(reward); } else { int reward = 0; speedMultiplier = 0f; boost = true; jumped = false; gb.UpdateLandingText("Landing: CRASH! +" + reward.ToString()); gb.DestroyMe(); } } #endregion #region rail trigger if (other.gameObject.CompareTag("GrindObject")) { isAboveRail = true; if (Input.GetAxis("Vertical") >= 0) { gb.DestroyMe(); } } else { isAboveRail = false; } #endregion }
void OnCollisionEnter2D(Collision2D other) { #region ground trigger if (other.gameObject.CompareTag("GroundCollider") && jumped) { float angle = Vector2.Angle(this.transform.right, rayCastRight.point - rayCastLeft.point); if (angle <= 15f) { int reward = 20; jumped = false; if (trickComplete) { BoostPlayer(2f); } gb.UpdateLandingText("Landing: Perfect! +" + reward); gb.UpdateScore(reward); } else if (angle <= 30f) { int reward = 15; if (trickComplete) { BoostPlayer(1.8f); } jumped = false; gb.UpdateLandingText("Landing: Great! +" + reward); gb.UpdateScore(reward); } else if (angle <= 45f) { int reward = 10; if (trickComplete) { BoostPlayer(1.6f); } jumped = false; gb.UpdateLandingText("Landing: Good! +" + reward); gb.UpdateScore(reward); } else if (angle <= 60f) { int reward = 5; if (trickComplete) { BoostPlayer(1.2f); } jumped = false; gb.UpdateLandingText("Landing: Alright +" + reward); gb.UpdateScore(reward); } else if (angle <= 90f) { int reward = 2; if (trickComplete) { BoostPlayer(0.5f); } jumped = false; gb.UpdateLandingText("Landing: Poor +" + reward); gb.UpdateScore(reward); } else { int reward = 0; gb.UpdateLandingText("Landing: CRASH! +" + reward); LocalDestroy(); } Vector3 targetVector = (rayCastRight.point - rayCastLeft.point).normalized; Quaternion toRotation = Quaternion.LookRotation(targetVector, Vector3.up); float maxAngleDelta = 15f; // rotates the player to be parallel to the ground transform.rotation = mRB.velocity.x > 0 ? Quaternion.RotateTowards(transform.rotation, toRotation, maxAngleDelta) : Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(-targetVector, Vector3.up), maxAngleDelta); mRB.AddForce(Vector3.Normalize(transform.right) * AddedSpeed); } #endregion #region rail trigger /* * if (other.gameObject.CompareTag("GrindObject")) * { * isAboveRail = true; * if (Input.GetAxis("Vertical") >= 0) * LocalDestroy(); * } * else * isAboveRail = false; */ #endregion }