Hello, I’m making a Survival horror game, and I need a way to get item source to spawn in the corresponding item when hit. I’ve tried Code Cobras “2D melee combat system” tutorial but it’s not working (doesn’t do damage) for some reason.
I would assume that you want to hit an Actor (Wood for example) and the Character will get some amount of wood back, right?
You can use Interface calls from your own interface. First, Actor Wood should implement Damage interface method that will bring the amount of damage together with the Actor that made this damage. In return the Wood Actor will send the interface call to the Damage Actor with the amount (float) of wood resource. So the CHaracter will get that call as it implementing this interface method and will get the amount of wood it need to store.
Let me know if you get my idea or if you need more details on that implementation.
More of, you hit a Resource source ex. “tree”, and then that spawns an object ex. “wood” that can be picked up as an item.
Ok, got you. So same approach, but when the Wood receives Damage Call you have made. There you can provide info like damage causer and the location and direction. Based on that you can spawn a log from the tree location and the opposite direction of the damage.
It will spawn a new actor, like a log, so the character can pick this up.
Let me know if you have more questions about this.
@SSneakythief I have created a sample project to show this:
I have created an interface with only hit result as this is big data and I’m reusing their variables:
Then I have created a tree actor and implemented this interface:
In my character I have made a line trace to see the tree and hit it when I press key, and it will send the call to the actor I hit. Also I have filled up HitResult with the data I need.
At the end here is the game example with the output of the hit result from the tree perspective.
You can re-use the data in hit result the way you want or add this data as separate variables in the interface. Do it the way you want.
Also you can use location of the tree and direction of the hit to spawn a new actor “log” by (multiplying direction by -1) plus the tree world location. This will drop the log towards the character.
BR
Hi, is this still relevant question or you have found a solution?
yup
Please mark the post that was the answer to your question as a solution.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.