How do I make spawn projectiles deal damage to the player?
So I tried my best looking up a solution and didn't have any luck, I recently made enemy character blueprints and I want the projectiles they spawn to deal damage to the player I already have it set up that I can kill them however I just can't figure out how to get them to deal damage to me.
Currently, I can take damage from my melee attackers as I have a blueprint in my character that will make the player take damage on component hit however because my ranged enemies are spawning brand new projectiles I don't know how I would go about making a script for those newly projectiles which don't have an origin besides the scene I put in for the projectile to spawn from I'm fairly new to scripting so any help would be appreciated.
it appears your using the first person template right? if thats the case the projectile your spawning is its own actor. which means you could just expand your current system by opening the projectile actor and adding in a on hit event which casts the hit actor to your players class (firstpersoncharacter) then drag off the return value and set the health.
personally i dont like that approach and believe you should make use of the in built damage system. with the built in system each character would have two events in your case, event any damage and event begin overlap. the event any damage handles any damage which is incoming to the character. the begin overlap for your example would be your attack and would make use of the apply damage node to do damage to the actors it overlaps.
below is an example of how your system could look (i didnt include the check for death since im lazy and you seem to know that bit). anyway as you can see in the picture we have event any damage which has a pin for damage incoming. we take that damage and subtract it from the health and thats all thats needed to receive damage. then theres your attack begin overlap, here you just need to use the apply damage node which only requires you to give it a actor and how much damage to apply. if the other actor doesnt have a event for receiving damage then its ignored without issue. so it basically is like saying i hit a thing i dont care what it is apply some damage, if the other thing doesnt know what to do with damage it doesnt do anything and just goes meh whatevs. ok getting a bit weird now but thats the basic idea and the two major nodes are built into the engine.
oh and this system can be easily applied to your projectile as well. on overlap or hit apply damage. thats all the script it would need.
Follow this question
Once you sign in you will be able to subscribe for any updates here