Only set spectator camera if player haven't spawned already. Don't spawn player if they switch to class pick screen.

This commit is contained in:
William Moberg
2016-03-07 15:05:37 +01:00
parent 0dfe00b406
commit 282e0bf7c4
2 changed files with 43 additions and 26 deletions
+13 -3
View File
@@ -18,6 +18,8 @@ bool PlayerDeathSystem::OnPlayerDeath(Events::PlayerDeath& e)
return false;
}
LOG_DEBUG("------ Player #%i died.", e.Player.ID);
createDeathEffect(e.Player);
// Delete player
@@ -36,6 +38,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
auto playerModel = player.FirstChildByName("PlayerModel");
if (!playerModel.Valid() || !playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) {
if (player == LocalPlayer) {
LOG_DEBUG("------ LocalPlayer's death effect could not be spawned, setting to spectator instead of death cam.");
setSpectatorCamera();
}
return;
@@ -57,6 +60,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
//camera (with lifetime) behind the player
if (player == LocalPlayer) {
LOG_DEBUG("------ LocalPlayer's death effect spawning, setting to death camera.");
m_LocalPlayerDeathEffect = deathEffectEW;
auto cam = deathEffectEW.FirstChildByName("Camera");
Events::SetCamera eSetCamera;
@@ -71,8 +75,14 @@ bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e)
if (m_LocalPlayerDeathEffect.ID != e.DeletedEntity) {
return false;
}
setSpectatorCamera();
// If the player hasn't spawned already, activate the spectator camera.
if (!LocalPlayer.Valid()) {
LOG_DEBUG("------ LocalPlayer's death effect removed, setting to spectator.");
setSpectatorCamera();
} else {
LOG_DEBUG("------ LocalPlayer's death effect removed, player is already spawned, not setting spectator.");
}
return true;
}
@@ -80,7 +90,7 @@ void PlayerDeathSystem::setSpectatorCamera()
{
// Look for the spectator camera entity in the level.
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) {
if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera")) {
return;
}
Events::SetCamera eSetCamera;