Recently, we've been developing more hazards for our levels. Thus, I volunteered to create platforms that would crumble after a player steps on them (after a set amount of time after the player touched it).
First, we knew this would be a trigger-able event, so using our trigger system seemed obvious. There were three important variables to keep track of for this event. First, the time it takes for the object to crumble after the player lands on it. Second, the time it takes for the object to fully crumble (i.e. the player can't stand on it any more). Third, the time it takes for the object to be restored (so the player can try again if he failed).
I handled most of the logic in the update function. When a crumble trigger event is activated, it sets a crumbling flag. The update function checks for this flag, and if it is true, it will count down the time it takes for the object to start crumbling. Once that timer has elapsed, it will trigger the flag for the object to crumble while disabling the crumbling flag. The update function works similarly to update the timer until it has elapsed (which will mean the object is no longer valid as a platform). Finally, the current flag is disabled, and the restore flag is enabled. Again, the update function will count down; once the restore timer has elapsed, the platform will reform (and, of course, the restore flag is disabled). The crumbling platform can then be triggered again.
There were a few problems with actually restoring the object again. I couldn't simply just delete the object when it crumbled, as I had to be able to restore it to its previous position. Thus, I had to be able to disable and re-enable three aspects of an object. The actual physics body has to be disabled, so the player wouldn't collide with it. The display model had to be disabled (or in essence invisible), so the player wouldn't see it. Finally, the trigger had to be disabled, so it couldn't be tripped pre-maturely. The display model was easy enough since there was an invisible toggle already implemented, but the other two were a bit more tricky.
In short, I collaborated with a few teammates to write enable/disable booleans for the physics body and trigger. When enabled, the physics body boolean would add the physics body to the physics engine, and the trigger boolean would simply ignore colliding information. The reverse is true when the variables are disabled.
With that obstacle out of the way, I had a working crumbling trigger that would destroy a platform after the player stepped on it, and then be restored after a set amount of time. It works rather well, and am looking forward to seeing it in action in our upcoming levels.
No comments:
Post a Comment