private bool DetectCollisionWithPlayerBullet(PlayerBulletBase bullet) { int nextColliderIndex = 0; int curColliderIndex; bool isCollided = false; do { CollisionDetectParas collParas = bullet.GetCollisionDetectParas(nextColliderIndex); curColliderIndex = nextColliderIndex; nextColliderIndex = collParas.nextIndex; if (collParas.type == CollisionDetectType.Circle) { // 子弹为圆形判定,先检测外切正方形 float dx = Mathf.Abs(_curPos.x - collParas.centerPos.x); float dy = Mathf.Abs(_curPos.y - collParas.centerPos.y); // 两圆的半径和 float sumOfRadius = _radius + collParas.radius; if (dx <= sumOfRadius && dy <= sumOfRadius) { if (dx * dx + dy * dy <= sumOfRadius * sumOfRadius) { bullet.CollidedByObject(curColliderIndex); isCollided = true; } } } } while (nextColliderIndex != -1); return(isCollided); }
private bool DetectCollisionWithPlayerBullet(PlayerBulletBase bullet) { int nextColliderIndex = 0; int curColliderIndex; bool isCollided = false; do { CollisionDetectParas collParas = bullet.GetCollisionDetectParas(nextColliderIndex); curColliderIndex = nextColliderIndex; nextColliderIndex = collParas.nextIndex; if (collParas.type == CollisionDetectType.Circle) { // 子弹为圆形判定,方形判定来检测 float dx = Mathf.Abs(_curPos.x - collParas.centerPos.x); float dy = Mathf.Abs(_curPos.y - collParas.centerPos.y); // 检测该碰撞矩形与方形是否相交 if (dx <= _halfWidth + collParas.radius && dy <= _halfHeight + collParas.radius) { CollidedByPlayerBullet(bullet, curColliderIndex); isCollided = true; } } } while (nextColliderIndex != -1); return(isCollided); }
public bool RegisterPlayerBullet(PlayerBulletBase bullet) { if (bullet == null) { return(false); } _playerBullets.Add(bullet); _playerBulletsCount++; _countOfPlayerBulletCreatedInFrame++; return(true); }
private void ShotBullet(PlayerBulletBase bullet) { var front = GetPlayerShipFront(); //自機の回転からQuaternionを取得 var playerTransform = transform; var playerQuaternion = Quaternion.Euler(playerTransform.eulerAngles); var offsetResult = playerQuaternion * bulletSpawnOffset; var p = playerTransform.position + (front * Time.deltaTime) + offsetResult; var r = playerTransform.rotation; bullet.SpawnBullet(p, r); }
public bool GetFreeBullet(out PlayerBulletBase bullet) { //Debug.Log("TryGet"); foreach (var b in poolBullets) { if (b.gameObject.activeSelf) { continue; } bullet = b; return(true); } bullet = null; return(false); }
private bool DetectCollisionWithPlayerBullet(PlayerBulletBase bullet) { int nextColliderIndex = 0; int curColliderIndex; bool isCollided = false; do { CollisionDetectParas collParas = bullet.GetCollisionDetectParas(nextColliderIndex); curColliderIndex = nextColliderIndex; nextColliderIndex = collParas.nextIndex; if (collParas.type == CollisionDetectType.Circle) { if (MathUtil.DetectCollisionBetweenCircleAndOBB(collParas.centerPos, collParas.radius, _curPos, _halfWidth, _halfHeight, _curRotation)) { CollidedByPlayerBullet(bullet, curColliderIndex); isCollided = true; } } } while (nextColliderIndex != -1); return(isCollided); }
/// <summary> /// 与玩家子弹发生碰撞 /// </summary> /// <param name="bullet"></param> /// <param name="curColliderIndex"></param> protected virtual void CollidedByPlayerBullet(PlayerBulletBase bullet, int curColliderIndex) { bullet.CollidedByObject(curColliderIndex); }