Since I've been looking at Nash's old platformer ZScript thing, I've noticed that he uses "track" for the camera. I would like to know more about this function, since I would like to implement some more sophisticated camera controls in my game (for example: locking down the camera on a certain axis). However, I can't find any documentation on this function and I've looked everywhere.
I would greatly appreciate the documentation.
What does "track" do? (ZScript)
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
-
- Posts: 360
- Joined: Mon May 08, 2017 3:23 am
- Graphics Processor: Intel with Vulkan/Metal Support
- Location: The Netherlands
Re: What does "track" do? (ZScript)
You mean track in 'if (track)' ? (line 9)
It's the player object; it's defined as SideScrollerPlayer, which inherits DoomPlayer (you can check that in player\SideScrollerPlayer).
What Nash is doing, is checking if the player exists. Before you refer in code to an object, it's best to always check if an object is existing, otherwise you could get those nasty null errors. So, only in the if block, when it's certain that a player exists, the camera is synced to the player's position.
Code: Select all
class SideScrollerCamera : SecurityCamera
{
// the player to track/scroll to
SideScrollerPlayer track;
override void Tick(void)
{
// position and point the camera to the player
if (track)
{
double cx = track.Pos.X;
double cy = track.Pos.Y + CAMERA_DISTANCE;
double cz = track.Pos.Z + CAMERA_HEIGHT;
Vector3 camPos = (cx, cy, cz);
SetOrigin(camPos, true);
Angle = CAMERA_ANGLE;
}
Super.Tick();
}
}
What Nash is doing, is checking if the player exists. Before you refer in code to an object, it's best to always check if an object is existing, otherwise you could get those nasty null errors. So, only in the if block, when it's certain that a player exists, the camera is synced to the player's position.
-
-
- Posts: 17481
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: What does "track" do? (ZScript)
I apologize for the overly-short or perhaps not-so-descriptive variable name but as gwHero already explained; it's a variable holding a reference (pointer) to a DoomPlayer-derived object called SideScrollerPlayer. The SideScrollerCamera needs to know which player to follow, hence why it's stored in that variable.
"track" is a local variable and it can be named anything, really. I could just as well name it "ThePlayerObjectThatThisCameraMustScrollAlongWith" but that would be annoying to type. :P
The "if (track)" part simply checks to make sure that the "track" variable is not empty before proceeding. If I had not added that check there, GZDoom would if the pointer to the player does not exist. And it may happen, depending on several factors not in my control.
People may write the same code as "if (track != NULL)" and I know some people are going to get anal about my overly-short null check but, meh, whatever... =P
"track" is a local variable and it can be named anything, really. I could just as well name it "ThePlayerObjectThatThisCameraMustScrollAlongWith" but that would be annoying to type. :P
The "if (track)" part simply checks to make sure that the "track" variable is not empty before proceeding. If I had not added that check there, GZDoom would if the pointer to the player does not exist. And it may happen, depending on several factors not in my control.
People may write the same code as "if (track != NULL)" and I know some people are going to get anal about my overly-short null check but, meh, whatever... =P