Introduction:

Today I added a new obstacle for the player that can only be removed by destroying it. This required both HP and destruction physics on new objects.

Obstacles:

First I had to create a new obstacle for the player to overcome. In this case I created a ramp with a large boulder (Indian Jones style) that is being held up by some planks. Once the planks are destroyed the boulder rolls down the ramp and the player can continue.

HP:

In order to have the planks fall apart I had to give the planks the ability to take damage. So I added an HP variable to the planks and implemented the blueprints that included the “Take Damage” event which reduces the plank HP to 0 after some damage is applied by the player. As a debugging tool I also added some text above the planks that displays the HP of the planks and updates in real time as they take damage.

Destruction:

Finally I added some blueprints that set the physics to enabled on the plank meshes once the HP reaches zero. This allows them to break apart realistically once they have been damaged enough by the player. Initially I thought this might be more complicated, but really it’s as simple as turning physics on once HP reaches zero, which allows the planks to move as you’d expect when broken.

One thing is that physics can get a little odd with small objects. Once the planks were destroyed the player had to walk over them. I’m sure there’s ways to make the planks react to being stepped on more realistically while leaving physics turned on, but this time since this is just a learning tutorial it was simpler to turn physics off a couple of seconds after they were destroyed, allowing the player to traverse them easily. Lastly I had the HP text disappear once it reaches zero.

Conclusion:

I could probably (and likely will) spend many hours working on physics stuff in the future. I would like to heavily focus on detailed damage models in my own games and really enjoy that kind feature in games.

Leave a Reply