Player/SpectateEntity

From Garry's Mod
Jump to: navigation, search
 Player:SpectateEntity( )

Contents

Description

Makes the player spectate the entity

To get the applied spectated entity, use Player:GetObserverTarget().

BUG

The player's position will not update while spectating, causing area portals and other map optimisations to not work properly. You can fix this by setting the player's position to the spectated entity's each tick.

Issue Tracker: #3267

Arguments

Entity entity

Entity to spectate.

Examples

Example

Creates a entity, spectates it and after 5 seconds, stops spectating it.

local ent = ents.Create( "prop_physics" )
ent:SetModel( "models/hunter/misc/sphere025x025.mdl" )
ent:SetPos( Vector( 0, 0, 0 ) )
ent:Spawn()
 
for _, ply in pairs( player.GetAll() ) do
	ply:Spectate( OBS_MODE_CHASE )
	ply:SpectateEntity( ent )
	ply:StripWeapons()

	timer.Simple( 5, function()
		ply:UnSpectate()
		ply:Spawn()
	end )
end


Personal tools
Navigation