kill system
does anybody know how to make a kill system like, if you have a weapon on hand and you are near an NPC, you press a button so it plays killing animations for both the NPC and the player and when the NPC's animation is finished they go into ragdoll
4 Replies
$unity
i only dabbled into game dev, but what u are describing is more than just one system/controller/behavior
eg the actual attack action:
u would play the animation for that attack, if its ranged u spawn bullet game objects that fly around and have a collider, if its a melee attack, u usually just have to spawn the collider.
some health or more global system would listen to events if these colliders and the attackable game object's colliders would intersect (basically if its a hit) to compute damage and so on.
which would trigger a new event if the game object's health went below 0
most animation systems in game engines allow to register for an event at a certain keyframe (eg the end of a dying animation), to execute further stuff.
so basically u would simply write a method that switches from the "normal" game object behaviour to the ragdoll and an event handler to listen for the dying animation
to trigger it for both the enemy and the player its then quite easy: give that health system a method to simply set them to be dead (no damage computation or what else still could come to mind)
basically u have some different systems and wire them all together via events
pretty rude to simply spam a tag.
u dont even know if they are using unity
personal opinion, but what i think what really helps alot for such system and more design decisions is to take a peek at what an Entity Component System (or short ECS) is.
tho note that they are designed for stuff where u have a lot of game objects (hundreds, maybe even thousands) and be fast at it.
tho to underline it, grasping their design helped me a lot to understand on how game systems and wiring these together is generally done
On top of what cap5lut said, a thing to do for optimisation is to first check if the player and npc are within range of each other.
There is no need to check for collisions if things are not even able to hit each other.
You can also use that check as a simple proof of concept, if they are within range and you "fire", play the animation.
It also might be worth seeing how fallout does it or other games that implement stuff like critical kill animations.