summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Entities/Player.cpp20
-rw-r--r--src/Entities/Player.h3
2 files changed, 21 insertions, 2 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 396069f0a..8876566da 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1703,6 +1703,23 @@ void cPlayer::SendRotation(double a_YawDegrees, double a_PitchDegrees)
+void cPlayer::SpectateEntity(cEntity * a_Target)
+{
+ if ((a_Target == nullptr) || (static_cast<cEntity *>(this) == a_Target))
+ {
+ GetClientHandle()->SendCameraSetTo(*this);
+ m_AttachedTo = nullptr;
+ return;
+ }
+
+ m_AttachedTo = a_Target;
+ GetClientHandle()->SendCameraSetTo(*m_AttachedTo);
+}
+
+
+
+
+
Vector3d cPlayer::GetThrowStartPos(void) const
{
Vector3d res = GetEyePosition();
@@ -2838,8 +2855,7 @@ void cPlayer::AttachTo(cEntity * a_AttachTo)
// Different attach, if this is a spectator
if (IsGameModeSpectator())
{
- m_AttachedTo = a_AttachTo;
- GetClientHandle()->SendCameraSetTo(*m_AttachedTo);
+ SpectateEntity(a_AttachTo);
return;
}
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 1ce2c5d9d..bea6e98f6 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -166,6 +166,9 @@ public:
*/
void SendRotation(double a_YawDegrees, double a_PitchDegrees);
+ /** Spectates the target entity. If a_Target is nullptr or a pointer to self, end spectation. */
+ void SpectateEntity(cEntity * a_Target);
+
/** Returns the position where projectiles thrown by this player should start, player eye position + adjustment */
Vector3d GetThrowStartPos(void) const;