To handle the damage the player character would receive, I made a "Take Damage" function in the Motion Controller Pawn, that could be called from any damage source.
Similarly to enemies, I also ended up needing to implement a short invulnerability period after any damage was received. This would prevent the player being easily overwhelmed by multiple sources of damage, and also help stop a single attack from dealing damage multiple times.
Originally I was going to make use of the Health component I developed earlier in the project, but since other members of the team had already set up variables for player health and were using them with other objects in the game, I opted to use the system they had set up instead.
While I think that our team's communication and organization has been generally very positive through most of the project, I definitely could have better communicated my ideas for systems like this early on in development.
Nevertheless, I was able to hook up the damage function to the hand health-bar that had been created by Luke.
Damage Indicators
When playing in VR, it was hard to notice when the player was taking damage. There wasn't any feedback to the player other than the healthbar around their wrists, which wouldn't be clearly visible a lot of the time.
To remedy this, we decided to add two main methods of feedback to the player:
A screen-space damage indicator
Camera shake
The screen-space damage indicator would display a quick red flash around the edges of the player's vision, while the camera shake would function similar to the one used when unlocking magic.
Death
At this point in development, we still hadn't decided or planned how player death would be handled. With not much time left, we kept it simple and went with a fade to black before respawning.
I had to look into achieve this specifically for our target platform, Oculus Quest. Unreal's normal camera functions for fading in and out are not compatible with the headset, and instead I had to use a function from Oculus' own library. Unfortunately as a result, the fade transition only renders to the headset's screen and can't be recorded to show here.
Since our game was made up of quite a few linear levels, many of which are being streamed in and out as the player progresses, we needed some form of checkpoints for the player to respawn at. This was pretty easy to achieve, just using an actor with a collision box that checks for when the player character overlaps it, updating the player's "Current Checkpoint" variable.
When the player character respawns, it simply resets its stats and moves to the current checkpoint's location.
Additionally, I added a custom event to the checkpoint blueprint that gets bound to the player character's own respawn event. This was done in case any checkpoint had actors other than the player that needed reset upon respawn, which ended up being the case for the checkpoint before the game's final boss.
Looking back, we likely left this mechanic far too late into development than we should have. I'd otherwise liked to have developed it further, with features like recording what items the player was holding or had in their holster to restore on respawn.
Comments