Skip to content

Commit

Permalink
Check for hitting respawn height before the collider under spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
oneVR committed Jan 20, 2021
1 parent 63d71f5 commit f94541d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Scripts/Editor/WorldDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,25 @@ public static Action FixSpawns(VRC_SceneDescriptor descriptor)
{
descriptor.spawns = new[] {descriptor.gameObject.transform};
}

descriptor.spawns = descriptor.spawns.Where(c => c != null).ToArray();

PrefabUtility.RecordPrefabInstancePropertyModifications(descriptor);
};
}

public static Action ChangeRespawnHeight(VRC_SceneDescriptor descriptor, float newHeight)
{
return () =>
{
Undo.RegisterCompleteObjectUndo(descriptor, "Respawn Height Change");

descriptor.RespawnHeightY = newHeight;

PrefabUtility.RecordPrefabInstancePropertyModifications(descriptor);
};
}

public static Action FixVRCProjectSettings(VRCProjectSettings settings)
{
return () =>
Expand Down Expand Up @@ -1302,6 +1315,10 @@ public static Action SetPostProcessingLayerResources(PostProcessLayer postProces
private const string NO_COLLIDER_UNDER_SPAWN_COMBINED = "Found {0} spawn points with no collider under them.";
private const string NO_COLLIDER_UNDER_SPAWN_INFO = "Spawning into a world with nothing to stand on will cause the players to fall forever.";

private const string RESPAWN_HEIGHT_ABOVE_COLLIDER = "The collider below spawn point \"{1}\" is below respawn height set in scene descriptor.";
private const string RESPAWN_HEIGHT_ABOVE_COLLIDER_COMBINED = "Found {0} spawn points where the collider is below the respawn height.";
private const string RESPAWN_HEIGHT_ABOVE_COLLIDER_INFO = "This will cause players to get stuck while respawning infinitely.";

private const string NO_PLAYER_MODS = "No Player Mods were found in the scene. Player mods are needed for adding jumping and changing walking speed.";

private const string TRIGGER_TRIGGER_NO_COLLIDER = "You have an OnEnterTrigger or OnExitTrigger Trigger \"{0}\" that does not have a Collider on it.";
Expand Down Expand Up @@ -1688,8 +1705,9 @@ private void CheckScene()
var spawnUnderRespawnHeight = general.AddMessageGroup(new MessageGroup(SPAWN_UNDER_RESPAWN_HEIGHT, SPAWN_UNDER_RESPAWN_HEIGHT_COMBINED, SPAWN_UNDER_RESPAWN_HEIGHT_INFO, MessageType.Error));
var noColliderUnderSpawn = general.AddMessageGroup(new MessageGroup(NO_COLLIDER_UNDER_SPAWN, NO_COLLIDER_UNDER_SPAWN_COMBINED, NO_COLLIDER_UNDER_SPAWN_INFO, MessageType.Error));
var colliderUnderSpawnTrigger = general.AddMessageGroup(new MessageGroup(COLLIDER_UNDER_SPAWN_IS_TRIGGER, COLLIDER_UNDER_SPAWN_IS_TRIGGER_COMBINED, COLLIDER_UNDER_SPAWN_IS_TRIGGER_INFO, MessageType.Error));
var respawnHeightAboveCollider = general.AddMessageGroup(new MessageGroup(RESPAWN_HEIGHT_ABOVE_COLLIDER, RESPAWN_HEIGHT_ABOVE_COLLIDER_COMBINED, RESPAWN_HEIGHT_ABOVE_COLLIDER_INFO, MessageType.Error));

for (int i = 0; i < sceneDescriptor.spawns.Length; i++)
for (var i = 0; i < sceneDescriptor.spawns.Length; i++)
{
if (sceneDescriptor.spawns[i] == null) continue;

Expand All @@ -1714,6 +1732,11 @@ private void CheckScene()
noColliderUnderSpawn.AddSingleMessage(new SingleMessage(spawn.gameObject.name).SetSelectObject(spawn.gameObject));
}
}
// Round respawn height to 2 decimals to reflect in-game functionality
else if (Math.Round(hit.point.y, 2) <= Math.Round(sceneDescriptor.RespawnHeightY, 2))
{
respawnHeightAboveCollider.AddSingleMessage(new SingleMessage(hit.collider.gameObject.name, spawn.gameObject.name).SetSelectObject(spawn.gameObject).SetAutoFix(ChangeRespawnHeight(sceneDescriptor, hit.point.y - 100)));
}
}
}
else
Expand Down

0 comments on commit f94541d

Please sign in to comment.