CenterPos CentoridPosition() { CenterPos centerPos = new CenterPos(); centerPos.position = (Vector2)gameManager.players[0].transform.position; float bestDistance = 0; int playerCount = 1; for (int i = 1; i < gameManager.players.Length; i++) { if (gameManager.IsPlayerValid(i)) { for (int j = 0; j < gameManager.players.Length; j++) { if (i == j || !gameManager.IsPlayerValid(j)) { continue; } float distance = Vector2.Distance(gameManager.players[i].transform.position, gameManager.players[j].transform.position); if (distance > bestDistance) { bestDistance = distance; } } centerPos.position += (Vector2)gameManager.players[i].transform.position; playerCount++; } } centerPos.distance = bestDistance; centerPos.position /= playerCount; return(centerPos); }
protected override void GenBullet() { EngineCore.Base.Point3D TmpPoint; for (int i = 0; i < ArrayNumA; i++) { for (int j = 0; j < ArrayNumB; j++) { if (!Bullets[i, j].IsEnabled) { //TmpPoint.x = Math.Cos(i) + i * Math.Cos(0.25 * j) + CenterPos.GetPosition().x; //TmpPoint.y = CenterPos.GetPosition().y; //TmpPoint.z = Math.Sin(i) - i * Math.Sin(0.25 * j) + CenterPos.GetPosition().z; TmpPoint.x = Math.Cos(i) + j * Math.Cos(0.25 * j) + CenterPos.GetPosition().x; TmpPoint.y = CenterPos.GetPosition().y; TmpPoint.z = Math.Sin(i) - j * Math.Sin(0.25 * j) + CenterPos.GetPosition().z; Bullets[i, j].SetPosition(TmpPoint); Bullets[i, j].SetScale(20, 20, 20); Bullets[i, j].IsEnabled = true; } TmpPoint.x = (Bullets[i, j].GetPosition().x - CenterPos.GetPosition().x) / 50; TmpPoint.y = 0; TmpPoint.z = (Bullets[i, j].GetPosition().z - CenterPos.GetPosition().z) / 50; TmpPoint.x = Bullets[i, j].GetPosition().x + TmpPoint.x; TmpPoint.y = Bullets[i, j].GetPosition().y + TmpPoint.y; TmpPoint.z = Bullets[i, j].GetPosition().z + TmpPoint.z; Bullets[i, j].SetPosition(TmpPoint); if (EngineCore.Base.Distance3D(Bullets[i, j].GetPosition(), CenterPos.GetPosition()) > GameRange) { Bullets[i, j] = new EngineCore.STG.Bullet(-2); } } } }
// Update is called once per frame void Update() { CenterPos center = CentoridPosition(); camera.transform.position = Vector2.MoveTowards(transform.position, new Vector3(center.position.x, center.position.y), moveSpeed * Time.deltaTime); camera.transform.position = new Vector3(camera.transform.position.x, camera.transform.position.y, zOffset); camera.orthographicSize = Mathf.MoveTowards(camera.orthographicSize, Mathf.Clamp((center.distance * sizeMultiplier) + sizeOffset, sizeMin, sizeMax), zoomSpeed * Time.deltaTime); }