Collision and Timeline Events

Posted by Josiah Purtlebaugh on Friday, August 21, 2020

Summary of accomplishment:

  • Learned widget blueprints and how to modify their values
  • Enabled collisions on weapons and enemies, and implemented collision events
  • Added a brief color change upon damaging an enemy
  • Added a health bar above the enemy’s head that follows camera rotation
  • Enabled ragdoll physics on enemy death

I started off today by implementing a simple health bar. It took me a few hours to implement for one simple reason: after creating the widget blueprint I could not figure out how to set the widget values from the enemy blueprint.

It seems like it should be obvious, but after adding the widget component to the enemy and dragging it into the event graph, I was not able to access any of the functions defined in the widget blueprint. What I didn’t understand is that even if you set the widget class in the widget component of the enemy blueprint, you still need to cast the widget to the correct widget class in the event graph before you can call its member functions.

Update Widget Values from Actor Blueprint

Next, I tried to sort out how to do collisions. Collisions were happening by default, but upon swinging the weapon the enemy would fly off into space. Hmm. Simulate physics was disabled, so it was nothing to do with ragdoll physics. Ultimately the issue seemed to the on the distinction between the collision types. I changed the weapon from BlockAll to OverlapAll and suddenly collisions were firing without the wacky model behavior.

Next, I went into the enemy blueprint and decided to make the color change upon collision. I did with the graph below.

React to Collisions

I am not sure how this will look once I start adding more conditional collisions, but hopefully it won’t become too messy.

Finally, I added enemy damage. This was as simple as lowering the currentHealth after each iteration of the timeline event (I really should do it before the timeline event). On each Tick I check the enemy health and if it is lower than or equal to zero, I delete the enemy actor. That was easy!

Ragdoll on Death