Fixed logic in `ArrangePlatforms` method. It leads to some errors and the "special condition" (count of 2 platforms) was unreachable.

atc-00
Aaron Carter 3 weeks ago
parent d1968054b6
commit 9b548f5af6
No known key found for this signature in database
GPG Key ID: 521C866B2B64DF6B

@ -90,23 +90,19 @@ namespace Unity.Multiplayer.Samples.BossRoom
SyncPlatformsClientRpc(platformIDs, arrangedPositions.ToArray());
}
List< Vector3 > ArrangePlatforms( List< Platform > activePlatforms ) {
const float startAngle = 90f ; // Start from top
private List<Vector3> ArrangePlatforms(List<Platform> activePlatforms)
{
int platformCount = activePlatforms.Count;
if (platformCount == 0)
{
if ( activePlatforms is not { Count: > 1, } ) {
Debug.LogError($"[ArrangePlatforms] No active platforms found!");
return new List<Vector3>();
return new( ) ;
}
float startAngle = 90f; // Start from top
List<Vector3> arrangedPositions = new List<Vector3>();
int platformCount = activePlatforms.Count ;
List< Vector3 > arrangedPositions = new( ) ;
// Special case: If 2 platforms, place them opposite to each other
if (platformCount == 2)
{
if ( platformCount is 2 ) {
arrangedPositions.Add(centerPoint.position + new Vector3(shapeRadius, 0, 0)); // Right side
arrangedPositions.Add(centerPoint.position + new Vector3(-shapeRadius, 0, 0)); // Left side
}
@ -114,19 +110,20 @@ namespace Unity.Multiplayer.Samples.BossRoom
{
float angleStep = 360f / platformCount;
for (int i = 0; i < platformCount; i++)
for (int i = 0; i < platformCount; ++i)
{
float angle = startAngle + (i * angleStep);
float radians = angle * Mathf.Deg2Rad;
Vector3 newPosition = new Vector3(
centerPoint.position.x + shapeRadius * Mathf.Cos(radians),
centerPoint.position.y,
centerPoint.position.z + shapeRadius * Mathf.Sin(radians)
);
Vector3 newPosition = new (
centerPoint.position.x + shapeRadius * Mathf.Cos(radians),
centerPoint.position.y,
centerPoint.position.z + shapeRadius * Mathf.Sin(radians)
);
arrangedPositions.Add(newPosition);
Debug.Log($"[ArrangePlatforms] Assigned position {i}: {newPosition} to Platform ID: {activePlatforms[i].PlatformID.Value}");
Debug.Log($"[ArrangePlatforms] Assigned position {i}: {newPosition} to Platform ID: " +
$"{activePlatforms[i].PlatformID.Value}");
}
}

Loading…
Cancel
Save