Friday, March 15, 2013

Checkpoints

We have recently been messing with triggers in our levels.  These, aptly named triggers, trigger certain events when a player collides with it.  The types of triggers we currently have are Quest Triggers, Ability Triggers, Killzone Triggers, and Load Model Triggers.  These are all quite important, but we all decided that we also needed a Checkpoint Trigger, so the player wouldn't have to attempt the entire level again if he/she happened to fail.

Thus, I was put on the task.  First, I had to learn about how our trigger system works (since I hadn't designed it).  After some research, I found out how we were handling triggers.  The actual trigger object is what the player collides into.  However, we add, or subscribe, these component-like trigger events to the trigger object.  When the trigger is tripped, all subscribed trigger events will activate.

With that in mind, all I had to create was the checkpoint trigger event. The checkpoint in this game needs to only store the position of the trigger that contains it.  However, the player needs to store the current valid checkpoint, so he/she can reference it when respawning.

Thus, I created a CheckpointTracker component for the player.  It kept track of the current checkpoint, and gave the checkpoint's position coordinates when ReturnToCheckpoint() was called.  I also added a function that kept track of the id number a checkpoint had.  This was implemented to prevent accidental checkpoint regressing; i.e. somehow a player skips a checkpoint, and then hits a further one.  We don't want the player to return to a skipped checkpoint, and suddenly lose progress for it. It's more of a safety precaution, but one that should help minimize such odd circumstances.

With that completed, all I had to do for the checkpoint trigger event was to subscribe it to the owning trigger,  and then supply the position/id number to the CheckpointTracker.  If the id number was greater than the current checkpoint, the supplied position would be registered as the new checkpoint (and the id number will be set to the supplied one).

I've tested out this trigger, and it works fantastically.  I even tested out a circumstance where I skipped a checkpoint and activated one farther away.  I then walked back to the previous one, and killed the avatar.  It spawned correctly at the checkpoint farther in the level, so I'm satisfied with this trigger event.

No comments:

Post a Comment