void Start() { animator = GetComponent <Animator>(); // boom AudioManager.Instance.PlayOneShot(AudioClipName.Explosion, 1.0f); // impart a force to all colliders withing range of the explosion. // The force will decrease with distance. // get the location of the explosion Vector3 explosionPos = transform.position; // get all colliders that lie within the explosion radius Collider2D[] colliders = Physics2D.OverlapCircleAll(new Vector2(explosionPos.x, explosionPos.y), radius); // iterate over all the colliders and apply a force to them foreach (Collider2D hit in colliders) { Rigidbody2D rb = hit.GetComponent <Rigidbody2D>(); // ignore everything except the player and the scenery obstacles if (rb != null && (rb.CompareTag(GameConstants.PLAYER) || rb.CompareTag(GameConstants.SCENERY_OBSTACLE))) { // apply force based on radius AddExplosionForce(rb, power, explosionPos, radius, upliftModifier); } } }
IEnumerator Reload() { reloading = true; yield return(new WaitForSeconds(reloadTime)); projectilesLeft = magazineSize; reloading = false; if (playerRb.CompareTag("Player")) { UIManager.Instance.SetBulletsCount(projectilesLeft, magazineSize); AudioManager.Instance.Play("Reload_" + Random.Range(0, 4)); } }
void FixedUpdate() { anim.SetFloat("VitHorEn", Mathf.Abs(rigidbody.velocity.x)); anim.SetFloat("VitVerEn", rigidbody.velocity.y); //Verifier si on a un ennemi de type 1 ou 2 pour lui donner le deplacement correct if (rigidbody.CompareTag("Ennemi")) { deplacer(-vitesse); } else if (rigidbody.CompareTag("EnnemiV2")) { DeplacerBidirection(rangeMouvement); } }
private void OnTriggerEnter2D(Collider2D other) { if (!rb2d.CompareTag("PlayerBullet") && (other.CompareTag("Player") || other.CompareTag("Player Inactive"))) { Debug.Log("Shot Player"); playerHealthScript.TakeDamage(); Destroy(gameObject); } else if (rb2d.CompareTag("PlayerBullet") && !other.GetComponent <BasicMovement>() /* && !other.CompareTag("Player Inactive")*/) { Debug.Log("Shot Enemy"); Destroy(other.gameObject); Destroy(gameObject); spawnManagerScript.EnemyDestroyed(); } }
private void ApplyBombBlast() { // Find all the colliders on the Enemies layer within the bombRadius. Collider2D[] enemies = Physics2D.OverlapCircleAll(transform.position, bombRadius, 1 << LayerMask.NameToLayer("Enemies")); // For each collider... foreach (Collider2D en in enemies) { // Check if it has a rigidbody (since there is only one per enemy, on the parent). Rigidbody2D rb = en.rigidbody2D; if (rb != null && rb.CompareTag("Enemy")) { // Find the Enemy script and set the enemy's health to zero. rb.gameObject.GetComponent <Vitality>().TakeLethalDamage(gameObject); // Find a vector from the bomb to the enemy. Vector3 deltaPos = rb.transform.position - transform.position; // Apply a force in this direction with a magnitude of bombForce. Vector3 force = deltaPos.normalized * bombForce; rb.AddForce(force); } } // Set the explosion effect's position to the bomb's position and play the particle system. explosionFX.transform.position = transform.position; explosionFX.Play(); }
void OnTriggerStay2D(Collider2D collision) { Rigidbody2D body = collision.GetComponent <Rigidbody2D> (); if (body && !body.CompareTag("Bullet")) { Vector2 forceToCentre = transform.position - collision.transform.position; Vector2 netForce = normForceDir + forceToCentre; body.AddForce(netForce.normalized * strength, ForceMode2D.Force); } }
private void FixedUpdate() { if (gameManager.gameStarted && !gameManager.gamePaused) { if (rb.CompareTag("Barrier")) { var currentTimer = 60 - (int)barrierTimer; Vector2 lookDir = _mousePos - rb.position; float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 180f - 3 * currentTimer; rb.rotation = angle; } else { Vector2 lookDir = _mousePos - rb.position; float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f; rb.rotation = angle; } } }
private void Push(Rigidbody2D target) { if (!target || !target.CompareTag("Player")) { return; } var direction = ((Vector2)transform.position - target.position).normalized; var dot = Mathf.Max(0, Vector2.Dot(-direction, transform.up)); print(dot); target.AddForce ( dot * pushScale * speed.Value * (target.position - (Vector2)transform.position), ForceMode2D.Impulse ); if (pushScale > 0 && audio) { audio.Play(); } }
private void Fire() { Vector2 direction = crosshairTransform.position - transform.position; // Part of testing firing position Vector2 tempFiringPos = Vector2.MoveTowards(transform.position, crosshairTransform.position, firingPosOffset); float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; Rigidbody2D formProjectile = Instantiate(projectile, tempFiringPos, Quaternion.Euler(0f, 0f, angle)) as Rigidbody2D; formProjectile.velocity = currentPower * CalculateAngle(direction); if (TurnSystem.Instance != null) { transform.parent.gameObject.GetComponent <Rigidbody2D>().freezeRotation = false; if (projectile.CompareTag("PassThrough")) { TurnSystem.Instance.Event_ShotFiredNoTracking(); } else { TurnSystem.Instance.Event_ShotFired(formProjectile.gameObject); } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("enemy") || collision.CompareTag("Player")) { Rigidbody2D hitRB2D = collision.GetComponent <Rigidbody2D>(); if (hitRB2D != null) { Vector2 difference = hitRB2D.transform.position - transform.position; difference = difference.normalized * thrust * 10; hitRB2D.AddForce(difference, ForceMode2D.Impulse); if (hitRB2D.CompareTag("Player")) { hitRB2D.gameObject.GetComponent <Player>().currentState = PlayerState.stagger; } else { hitRB2D.gameObject.GetComponent <EnemyAI>().currentState = EnemyState.stagger; } StartCoroutine(KnockCo(hitRB2D, collision.tag)); } } }