- Home /
Bullet Damage on different Limbs
Hello, i'm currently working on a bullet damage system, where I want to have different areas on the body that have different damage modifiers, the head, the body, and the limbs, where the head has a 2.5x damage modifier, the body has a 1x modifier, and the limbs a 0.5x modifier. My problem is how do I detect which part of the body has been hit.
Currently I just have a gameobject of the target i'm using, with a script attached to it that handles the health of the target
In that gameobject, I created 3 empty gameobjects, and put box colliders on each one, and gave them separate tags depending on what they were. I set the colliders to Trigger on these so that the bullet could pass through them and hit the target
So, my bullet is a physical sphere, which has a script that detects collisions, and applies bullet holes at the contact point. I'm wondering when the bullet hits the target, how would I detect which part of the body was hit / which box collider did the bullet pass through. Since my bullet isn't a trigger, i've noticed that the bullet passes through the box colliders without any collisions (when using ontriggerenter). Does anyone have any ideas how I can achieve this system?
If your bullet has a rigidbody and non-trigger collider, it should register trigger colliders. However, it's likely that it goes too fast for that because it might start in fron of the trigger in one frame and travel far enough to go completely through it for the next frame. There are workarounds to this problem, including one on the user wiki IIRC. It involves casting a ray from the last frame's position to the current one and see if the ray hit anything.
Once the colliders are registered, just compare the tag.
Answer by JeevanjotSingh · Feb 04, 2017 at 02:24 PM
Just create script for each of your box collider (Or body part) and assign different damage value to them when the Game Object (Bullet) enter trigger.
It's like create Gameobject public variable and drag the object (Bullet) into that and assign that script into all of box colliders . Now check if triggered object tag was something and assign damage that way .
REF - https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
https://docs.unity3d.com/ScriptReference/GameObject-tag.html
Your answer
Follow this Question
Related Questions
Raycast from inside an object 2 Answers
Character Controller Child Collisions 2 Answers
How can i make a raycast in my fps game? 1 Answer
2D shooter, 3d or 2d colliders? 2 Answers
How to get GameObject with its tag when ignoring Collision? 2 Answers