// Update is called once per frame void Update() { bool outOfBoundsX = false, outOfBoundsY = false; outOfBoundsX = this.transform.position.x <(m_dragScript.m_topLeft.position.x + m_dragScript.m_ballRadius) || this.transform.position.x> (m_dragScript.m_bottomRight.position.x - m_dragScript.m_ballRadius); outOfBoundsY = this.transform.position.y > (m_dragScript.m_topLeft.position.y - m_dragScript.m_ballRadius) || this.transform.position.y < (m_dragScript.m_bottomRight.position.y + m_dragScript.m_ballRadius); if (outOfBoundsX || outOfBoundsY) { StartCoroutine("DestroyBall"); m_cameraShake.AddShake(m_rb.velocity * 0.5f); if (outOfBoundsX) { m_rb.velocity = new Vector2(-m_rb.velocity.x, m_rb.velocity.y); this.transform.position = new Vector3(Mathf.Min(Mathf.Max(m_dragScript.m_topLeft.position.x + m_dragScript.m_ballRadius, this.transform.position.x), m_dragScript.m_bottomRight.position.x - m_dragScript.m_ballRadius), this.transform.position.y, this.transform.position.z); } if (outOfBoundsY) { m_rb.velocity = new Vector2(m_rb.velocity.x, -m_rb.velocity.y); this.transform.position = new Vector3(this.transform.position.x, Mathf.Max(Mathf.Min(m_dragScript.m_topLeft.position.y - m_dragScript.m_ballRadius, this.transform.position.y), m_dragScript.m_bottomRight.position.y + m_dragScript.m_ballRadius), this.transform.position.z); } } }
// Update is called once per frame void Update() { if (!m_bouncingUp) { if (m_currentBounceTime < m_bounceTime) { m_currentBounceTime += Time.deltaTime; if (m_currentBounceTime >= m_bounceTime) { m_currentBounceTime = m_bounceTime; m_bouncingUp = true; //Trigger camera shake m_cameraShake.AddShake(Vector2.down); } } } else { if (m_currentBounceTime > 0f) { m_currentBounceTime -= Time.deltaTime; if (m_currentBounceTime <= 0.0f) { m_currentBounceTime = 0.0f; m_bouncingUp = false; } } } this.transform.position = Vector3.Lerp(m_initialPos, m_finalPos, Mathf.Pow(1f - Mathf.Cos(m_currentBounceTime / m_bounceTime * Mathf.PI * 0.5f), 1.5f)); }
protected virtual bool FireProjectile(Vector2 position, Vector2 direction, TankWeaponHolder holder) { bool wasFired = false; for (int i = 0; i < weaponFiringOffsets.Length; i++) { Quaternion rotation = holder.transform.rotation; Vector2 offsetPosition = position + (Vector2)(rotation * weaponFiringOffsets[i].position); Vector2 offsetDirection = Quaternion.Euler(0, 0, weaponFiringOffsets[i].angle) * direction; wasFired = true; Collider2D overlapCollider = Physics2D.OverlapPoint(offsetPosition, CollideOnSpawnLayermask); if (overlapCollider) { continue; } WeaponData weaponData = new WeaponData() { ownerTank = holder.ownerTank, weapon = this, holder = holder }; if (holder.ownerTank is PlayerTankManager) { weaponData.useCustomColour = true; weaponData.shotCustomColour = (holder.ownerTank as PlayerTankManager).colour; } projectile.OnFired(offsetPosition, offsetDirection, weaponData); } CameraShake.AddShake(shakeAmount, Quaternion.FromToRotation(Vector2.up, direction)); // Sorry jordan, I broke this and I have no idea what the value should be :( return(wasFired); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Attack") { Camera.main.backgroundColor = Color.red; Time.timeScale = 0.01f; cameraShake.AddShake(0.1f, 5.0f); } }
protected virtual void Quake() { float maxDist = 50; float dist = Vector3.Distance(GlobalSettings.PlayerPosition, transform.position); if (dist < maxDist) { float shake = (maxDist - dist) / (maxDist * 10); cs.AddShake(new Shake(shake, 1, shake)); } // Add sound ? }