Classes:SpectatorCamera
Jump to navigation
Jump to search
Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub. |
Note: Wait! Stop! You do not need to copy this actor's code into your project! Here's why:
|
SpectatorCamera | |||
---|---|---|---|
Actor type | Internal | Game | (ZDoom) |
DoomEd Number | None | Class Name | SpectatorCamera |
Classes: SpectatorCamera
→All other classes
(New from 4.13.0)
Spectator Camera is meant to look at and follow an actor (pointed to by its tracer field) from a constant angle and pitch. This is achieved via the use of its ViewPos field. So the camera viewpoint's position is typically different from the camera actor's position.
Properties
- SpectatorCamera.lagdistance value
- Sets the lag distance between the camera's (not the viewpoint's) and its tracer's position above which a lazy-follow gets triggered and the camera chases the tracer.
- Default is 0.0.
- SpectatorCamera.chasemode value
- Integer that determines type of lazy follow. The behavior is:
- 0 - chase tracer until positions are equal.
- 1 - same as 0, but move only when the tracer is moving.
- 2 (or above) - stops chasing if tracer comes within lag distance of camera position (not viewpoint position).
- Default is 0.
- SpectatorCamera.chasemode value
- A boolean property that indicates whether a lazy-follow condition has been triggered.
Methods
- void Init(double dist, double yaw, double inpitch, int inflags)
- The camera viewpoint's position can be initialized to be a distance dist away from and looking at the camera actor's position from an angle yaw and pitch inpitch. The inflags argument are to supply the ViewPosition flags. Typically, the flag VPSF_ABSOLUTEOFFSET is set.
- void LookAtSelf(double inpitch)
- Adjusts angle such that the viewpoint is looking at the camera actor's position. Sets pitch to inpitch. Used by Init.
ZScript definition
class SpectatorCamera : Actor
{
bool chasingtracer;
double lagdistance; // camera gives chase (lazy follow) if tracer gets > lagdistance away from camera.pos
int chasemode; // 0: chase until tracer centered, 1: same but only when tracer is moving, 2: stop chase if tracer within lagdistance
property lagdistance : lagdistance;
property chasingtracer : chasingtracer;
property chasemode : chasemode;
default
{
+NOBLOCKMAP
+NOGRAVITY
+NOINTERACTION
RenderStyle "None";
CameraHeight 0;
SpectatorCamera.chasingtracer false;
SpectatorCamera.lagdistance 0.0;
SpectatorCamera.chasemode 0;
}
void Init(double dist, double yaw, double inpitch, int inflags)
{
double zshift = 0.0;
if(tracer != NULL)
{
if(player != NULL) zshift = -0.25*tracer.height;
else zshift = 0.5*tracer.height;
}
else if (player != NULL && player.mo != NULL) zshift = -0.5*player.mo.height;
SetViewPos((-dist*Cos(yaw)*Cos(inpitch), -dist*Sin(yaw)*Cos(inpitch), dist*Sin(inpitch)+zshift), inflags);
LookAtSelf(inpitch);
}
void LookAtSelf(double inpitch)
{
if(ViewPos.Offset.length() > 0.)
{
Vector3 negviewpos = (-1.0) * ViewPos.Offset;
angle = negviewpos.Angle();
pitch = inpitch;
}
}
override void Tick()
{
if(tracer != NULL)
{
Vector3 distvec = tracer.pos - pos;
double dist = distvec.length();
if((dist <= 4 && chasingtracer) || lagdistance <= 0.0) // Keep tracer centered on screen
{
SetOrigin(tracer.pos, true);
chasingtracer = false;
}
else // Lazy follow tracer
{
if(dist >= 2*lagdistance)
{
SetOrigin(tracer.pos, true);
chasingtracer = false;
}
else if(dist > lagdistance && !chasingtracer) chasingtracer = true;
if(chasingtracer)
{
speed = tracer.vel.xy.length()/dist;
if((speed == 0.0) && (chasemode == 0)) speed = tracer.speed/dist;
SetOrigin(pos + 2*distvec*speed, true);
if(chasemode > 1) chasingtracer = false;
}
}
}
else if(player != NULL && player.mo != NULL)
{
cameraFOV = player.FOV;
SetOrigin(player.mo.pos, true);
}
}
}
Categories:
- Chex Quest actors
- Chex Quest internal actors
- Chex Quest 3 actors
- Chex Quest 3 internal actors
- Doom actors
- Doom internal actors
- Doom II actors
- Doom II internal actors
- Heretic actors
- Heretic internal actors
- Hexen actors
- Hexen internal actors
- Strife actors
- Strife internal actors
- ZDoom actors
- ZDoom internal actors
- Internal