]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix angles not being applied correctly when a spectator becomes observer because...
authorterencehill <piuntn@gmail.com>
Mon, 23 Sep 2024 22:02:33 +0000 (00:02 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 23 Sep 2024 22:02:33 +0000 (00:02 +0200)
qcsrc/server/client.qc

index 92256c58f734dbd2e2efd4e2ff8e1cb049b619cd..74c533aff22983f666135dc185db57c28d458120 100644 (file)
@@ -248,6 +248,7 @@ entity SelectObservePoint(entity this)
        return RandomSelection_chosen_ent;
 }
 
+.entity spot_save;
 /** putting a client as observer in the server */
 void PutObserverInServer(entity this, bool is_forced, bool use_spawnpoint)
 {
@@ -282,6 +283,10 @@ void PutObserverInServer(entity this, bool is_forced, bool use_spawnpoint)
                        spot = SelectSpawnPoint(this, true);
                if (!spot) LOG_FATAL("No spawnpoints for observers?!?");
 
+               // in case a spectator becomes observer because the spectated player disconnects
+               // the engine will revert the angles we set here, so we have to save spot and
+               // apply angles later in this frame again
+               this.spot_save = spot;
                this.angles = vec2(spot.angles);
                // offset it so that the spectator spawns higher off the ground, looks better this way
                setorigin(this, spot.origin + (is_observepoint ? '0 0 0' : autocvar_sv_player_viewoffset));
@@ -3034,6 +3039,13 @@ void PlayerFrame (entity this)
                float hp = healtharmor_maxdamage(GetResource(this, RES_HEALTH), GetResource(this, RES_ARMOR), autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x;
                WaypointSprite_UpdateHealth(this.waypointsprite_attachedforcarrier, hp);
        }
+
+       if (this.spot_save && IS_OBSERVER(this))
+       {
+               this.angles = vec2(this.spot_save.angles);
+               this.fixangle = true;
+               this.spot_save = NULL;
+       }
 }
 
 // hack to copy the button fields from the client entity to the Client State