This article's documentation is for anything that uses the Source engine. Click here for more information.

Difference between revisions of "Point viewcontrol"

From Valve Developer Community
Jump to: navigation, search
(Add VScript code to fix camera stuck issues in TF2)
 
Line 6: Line 6:
 
{{bug|The camera doesn't follow its path correctly. It will not follow paths at all if it doesn't have an <code>Entity to Look At</code> set.}}
 
{{bug|The camera doesn't follow its path correctly. It will not follow paths at all if it doesn't have an <code>Entity to Look At</code> set.}}
 
{{bug|The camera ignores the <code>New Train Speed</code> keyvalue and <code>Teleport to THIS path_corner</code> spawnflag on [[path_track]]s.}}
 
{{bug|The camera ignores the <code>New Train Speed</code> keyvalue and <code>Teleport to THIS path_corner</code> spawnflag on [[path_track]]s.}}
{{bug|The camera fails to function when parented, [[logic_measure_movement]] can be used as a workaround. (Fixed in {{portal2}} and onward.)}}
+
{{bug|The camera fails to function when parented in Hammer, [[logic_measure_movement]] can be used as a workaround. (Fixed in {{portal2}} and onward.)}}
 
{{bug|If the camera is killed while active, or the player suicides, the camera will be stuck permanently on the player's screen. The only fix afterwards is for the player to reconnect to the server. For {{tf2}}, see the [[VScript]] code below to fix this issue.}}
 
{{bug|If the camera is killed while active, or the player suicides, the camera will be stuck permanently on the player's screen. The only fix afterwards is for the player to reconnect to the server. For {{tf2}}, see the [[VScript]] code below to fix this issue.}}
 
{{bug|For {{tf2}}{{l4d2}}, {{Code|select=1|{{ent|point_viewcontrol}}}} makes the player invulnerable while enabled on camera. However, {{Code|select=1|{{ent|point_viewcontrol_survivor}}}} and {{Code|select=1|{{ent|point_viewcontrol_multiplayer}}}} don't.}}
 
{{bug|For {{tf2}}{{l4d2}}, {{Code|select=1|{{ent|point_viewcontrol}}}} makes the player invulnerable while enabled on camera. However, {{Code|select=1|{{ent|point_viewcontrol_survivor}}}} and {{Code|select=1|{{ent|point_viewcontrol_multiplayer}}}} don't.}}

Latest revision as of 13:54, 26 March 2024

Point viewcontrol.png
class hierarchy
CTriggerCamera defined in triggers.cpp
CBaseEntity

point_viewcontrol is a point entity available in all Source Source games. It is a camera entity that controls the player's view. While it's active, the player will see out of the camera.

Note.pngNote:This entity has many problems. See the discussion page for full descriptions and fixes.
Icon-Bug.pngBug:The camera doesn't follow its path correctly. It will not follow paths at all if it doesn't have an Entity to Look At set.
Icon-Bug.pngBug:The camera ignores the New Train Speed keyvalue and Teleport to THIS path_corner spawnflag on path_tracks.
Icon-Bug.pngBug:The camera fails to function when parented in Hammer, logic_measure_movement can be used as a workaround. (Fixed in Portal 2 and onward.)
Icon-Bug.pngBug:If the camera is killed while active, or the player suicides, the camera will be stuck permanently on the player's screen. The only fix afterwards is for the player to reconnect to the server. For Team Fortress 2, see the VScript code below to fix this issue.
Icon-Bug.pngBug:For Team Fortress 2Left 4 Dead 2, point_viewcontrol makes the player invulnerable while enabled on camera. However, point_viewcontrol_survivor and point_viewcontrol_multiplayer don't.
Icon-Bug.pngBug:In Team Fortress 2, if the map switches during intermission while a player has a camera enabled, the camera will persist into the next map! The VScript code below will fix this.
Tip.pngTip:Copy the following VScript code to a .nut file and assign it to every point_viewcontrol as an Entity Script.

if (!("SetInputHook" in getroottable()))
{
	::_PostInputScope <- null;
	::_PostInputFunc  <- null;

	::SetInputHook <- function(entity, input, pre_func, post_func)
	{
		entity.ValidateScriptScope();
		local scope = entity.GetScriptScope();
		if (post_func)
		{
			local wrapper_func = function() 
			{ 
				_PostInputScope = scope; 
				_PostInputFunc  = post_func;
				if (pre_func)
					return pre_func.call(scope);
				return true;
			};
			
			scope["Input" + input]           <- wrapper_func;
			scope["Input" + input.tolower()] <- wrapper_func;
		}
		else if (pre_func)
		{
			scope["Input" + input]           <- pre_func;
			scope["Input" + input.tolower()] <- pre_func;
		}
	}
	
	getroottable().setdelegate(
	{
		_delslot = function(k)
		{
			if (_PostInputScope && k == "activator" && "activator" in this)
			{
				_PostInputFunc.call(_PostInputScope);
				_PostInputFunc = null;
			}
			
			rawdelete(k);
		}
	});		
}

if (!("CameraFixer" in getroottable()))
{
	::_CameraFixLifestate <- 0;

	::CameraFixPre <- function()
	{
		if (activator)
		{
			_CameraFixLifestate = NetProps.GetPropInt(activator, "m_lifeState");
			NetProps.SetPropInt(activator, "m_lifeState", 0);
			NetProps.SetPropEntity(self, "m_hPlayer", activator);
		}
		
		return true;
	}

	::CameraFixPost <- function()
	{
		if (activator)
		{
			NetProps.SetPropInt(activator, "m_lifeState", _CameraFixLifestate);
			NetProps.SetPropInt(activator, "m_takedamage", 2);
		}
	}
	
	::CameraDisableAll <- function()
	{
		for (local player; player = Entities.FindByClassname(player, "player");)
			EntFireByHandle(CameraFixer, "Disable", "", -1, player, player);
		EntFireByHandle(CameraFixer, "Kill", "", 1, null, null);
	}
	
	::CameraFixer <- Entities.CreateByClassname("point_viewcontrol");
	::CameraFixer.KeyValueFromString("classname", "camera_fixer");
	::CameraFixer.AddEFlags(1);
	SetInputHook(CameraFixer, "Disable", CameraFixPre, CameraFixPost);	

	SpawnEntityFromTable("logic_eventlistener", 
	{ 
		classname	 = "move_rope",
		eventname    = "teamplay_round_start",
		IsEnabled    = true,
		OnEventFired = "worldspawn,CallScriptFunction,CameraDisableAll,-1,-1",
	});

	SpawnEntityFromTable("logic_eventlistener", 
	{ 
		classname	 = "move_rope",
		eventname    = "recalculate_holidays",
		IsEnabled    = true,
		OnEventFired = "worldspawn,RunScriptCode,if (GetRoundState() == 8) CameraDisableAll(),0.1,-1",
	});
}

function Precache()
{
	SetInputHook(self, "Disable", CameraFixPre, CameraFixPost);
}

Keyvalues


Targetname:
Name (targetname) <string>
The targetname that other entities refer to this entity by.
Entity to Look At (target) <targetname>
Name of the entity that the camera should point at and track while active.
Target Attachment Name (targetattachment) <string>
If set, the camera will focus on the specified attachment on the 'Entity to Look At'.
Hold Time (wait) <integer>
The amount of time the camera should control the player's view for, after which it deactivates itself. If the camera should stay active until told to deactive, set the 'Infinite Hold Time' spawnflag.
Path Corner (moveto) <targetname>
The first path corner in a track that the camera should move along once it's activated. If not specified, the camera won't move.
Interpolate Position To Player (interpolatepositiontoplayer) <boolean> (only in Half-Life 2: Episode One Half-Life 2: Episode Two)
Gradually interpolate player's position to here on start.
Initial Speed (speed) <string>
The starting speed that the camera moves at, if it's on a path track.
Acceleration units/sec^2 (acceleration) <string>
The speed at which the camera accelerates to path corner's desired speeds.
Stop Deceleration units/sec^2 (deceleration) <string>
The speed at which the camera decelerates to path corner's desired speeds.
FOV (fov) <float> (in all games since Alien Swarm) (also in Garry's Mod) !FGD
The FOV when using this camera.
Note.pngNote:Not present in Alien Swarm's FGD, but present in all FGDs onward.
FOV rate (fov_rate) <float> (in all games since Alien Swarm) (also in Garry's Mod) !FGD
How fast we change to the new FOV.
Note.pngNote:Not present in Alien Swarm's FGD, but present in all FGDs onward.
Tracking Speed of the camera (trackspeed) <float> (in all games since Portal 2) (also in Garry's Mod)
The speed that the camera tries to follow its look target.

Angles:
Pitch Yaw Roll (Y Z X) (angles) <angle>
This entity's orientation in the world. Pitch is rotation around the Y axis, yaw is the rotation around the Z axis, roll is the rotation around the X axis.

Flags

  •  [1] : Start At Player
       Start the camera at the player's position.
    Icon-Bug.pngBug:Breaks the camera movement if the player was still moving when the camera activated.
  •  [2] : Follow Player
       This is the same as if you set the lookat target to !player.
    Icon-Bug.pngBug:Causes camera issues in multiplayer.
  •  [4] : Freeze Player
       Stop recognizing input from the player.
  •  [8] : Infinite Hold Time
       Ignore the hold time, and stay activated until explicitly disabled.
  •  [16] : Snap to goal angles
  •  [32] : Make Player non-solid
  •  [64] : Interruptable by Player
       If the player presses +Use, disable.
  •  [128] : Set FOV (in all games since Alien Swarm) (also in Garry's Mod) !FGD
      
    Note.pngNote:Not present in Alien Swarm's FGD, but present in all FGDs onward.

Inputs

Enable
Enable the point_viewcontrol, and start controlling the player's view.
Disable
Disable the point_viewcontrol, and stop controlling the player's view.
SetTarget <string> (in all games since Portal 2) (also in Garry's Mod)
Set a new target for the camera to point at.
SetTargetAttachment <string> (in all games since Portal 2) (also in Garry's Mod)
Set a new attachment on the target for the camera to point at.
ReturnToEyes  (in all games since Portal 2) (also in Garry's Mod)
Return the camera view to the player's eyes.
TeleportToView  (in all games since Portal 2) (also in Garry's Mod)
Teleport the player to the current position of the camera.
SetTrackSpeed <float> (in all games since Portal 2) (also in Garry's Mod)
Set the speed that the camera will try to track it's target.
SetPath <string> (in all games since Portal 2) (also in Garry's Mod)
Have the camera start following a new path.

Outputs

OnEndFollow
Fired when the point_viewcontrol deactivates, due to the Disable input being received, the Entity to Look At being destroyed, or the Hold Time expiring.