protected void SpawnBullet() { //we check if there is a wall between the player and the bullet spawn position, if there is, we don't spawn a bullet //otherwise, the player can "shoot throught wall" because the arm extend to the other side of the wall Vector2 testPosition = transform.position; testPosition.y = m_CurrentBulletSpawnPoint.position.y; Vector2 direction = (Vector2)m_CurrentBulletSpawnPoint.position - testPosition; float distance = direction.magnitude; direction.Normalize(); RaycastHit2D[] results = new RaycastHit2D[12]; if (Physics2D.Raycast(testPosition, direction, m_CharacterController2D.ContactFilter, results, distance) > 0) { return; } BulletObject bullet = bulletPool.Pop(m_CurrentBulletSpawnPoint.position); bool facingLeft = m_CurrentBulletSpawnPoint == facingLeftBulletSpawnPoint; bullet.rigidbody2D.velocity = new Vector2(facingLeft ? -bulletSpeed : bulletSpeed, 0f); bullet.spriteRenderer.flipX = facingLeft ^ bullet.bullet.spriteOriginallyFacesLeft; rangedAttackAudioPlayer.PlayRandomSound(); }
public new void Shooting() { Vector2 shootPosition = shootingOrigin.transform.localPosition; //if we are flipped compared to normal, we need to localy flip the shootposition too if ((spriteFaceLeft && m_SpriteForward.x > 0) || (!spriteFaceLeft && m_SpriteForward.x > 0)) { shootPosition.x *= -1; } BulletObject obj = m_BulletPool.Pop(shootingOrigin.TransformPoint(shootPosition)); BulletObject obj2 = m_BulletPool.Pop(shootingOrigin.TransformPoint(shootPosition)); BulletObject obj3 = m_BulletPool.Pop(shootingOrigin.TransformPoint(shootPosition)); shootingAudio.PlayRandomSound(); float x = (m_TargetShootPosition - shootingOrigin.transform.position).x; Vector3 vectorHigh = new Vector3(x, 10, 0); Vector3 vectorMedium = new Vector3(x, 5, 0); Vector3 vectorLow = new Vector3(x, 2, 0); obj.rigidbody2D.velocity = vectorHigh; obj2.rigidbody2D.velocity = vectorMedium; obj3.rigidbody2D.velocity = vectorLow; }
public void Shooting() { Vector2 shootPosition = shootingOrigin.transform.localPosition; //if we are flipped compared to normal, we need to localy flip the shootposition too if ((spriteFaceLeft && m_SpriteForward.x > 0) || (!spriteFaceLeft && m_SpriteForward.x > 0)) { shootPosition.x *= -1; } BulletObject obj = m_BulletPool.Pop(shootingOrigin.TransformPoint(shootPosition)); shootingAudio.PlayRandomSound(); obj.rigidbody2D.velocity = (GetProjectilVelocity(m_TargetShootPosition, shootingOrigin.transform.position)); }
public void Shooting2() { Vector2 shootPosition = shootingOrigin.transform.localPosition; int x = 0; //if we are flipped compared to normal, we need to localy flip the shootposition too if ((spriteFaceLeft && m_SpriteForward.x > 0) || (!spriteFaceLeft && m_SpriteForward.x > 0)) { shootPosition.x *= -1; x = 10; } else { x = -10; } BulletObject obj = m_BulletPool.Pop(shootingOrigin.TransformPoint(shootPosition)); shootingAudio.PlayRandomSound(); obj.rigidbody2D.velocity = new Vector3(x, 0, 0); }
protected void SpawnBullet() { //we check if there is a wall between the player and the bullet spawn position, if there is, we don't spawn a bullet //otherwise, the player can "shoot throught wall" because the arm extend to the other side of the wall Vector2 testPosition = transform.position; testPosition.y = m_CurrentBulletSpawnPoint.position.y; Vector2 direction = (Vector2)m_CurrentBulletSpawnPoint.position - testPosition; float distance = direction.magnitude; direction.Normalize(); RaycastHit2D[] results = new RaycastHit2D[12]; if (Physics2D.Raycast(testPosition, direction, m_CharacterController2D.ContactFilter, results, distance) > 0) { return; } BulletObject bullet = bulletPool.Pop(m_CurrentBulletSpawnPoint.position); Vector2 v = new Vector2(Mathf.Cos(arm.eulerAngles.z * Mathf.Deg2Rad), Mathf.Sin(arm.eulerAngles.z * Mathf.Deg2Rad)); bullet.rigidbody2D.velocity = bulletSpeed * v; }