Can someone help me with the spike trap?

Right now, I am making a Sonic game. In Sonic games, when Sonic gets hit by a spike trap, he’ll lose rings. Hit again, he’ll lose a life. I want it to be just like the Sonic games. Keep in mind that I am using Blueprints. I just made the spike trap using meshes, and I am doing the functions.

Here is the setting so far. I also want to add some invincibility to this.

I’m putting this functionality in the BP_PlayerCharacter blueprint.

I even made a ring functionality for this.

Can somebody help me here?

Hey!
I strongly recommend you to use the already built-in “damage system”.
Each actor can receive damage (if CanBeDamaged is true) with the Apply Damage function.
When an actor received any damage, the event AnyDamage of that actor will be called.

What that means for you:
In the spike trap, apply damage to the overlapped actor.
In your player character, override the AnyDamage event and implement your damage logic.
For instance you first subtract the rings by one, if no rings are left, subtract the damage from the players health.
Once no health is left, implement some death mechanic.

1 Like