I’m currently trying to create a very simple zombie-shooter-esque game for a school project. In the game, you need to fight zombies with guns. (yes I know very original.) For the hostiles, I created an empty gameobject with rigidbody that has all the coding attached, and each bodypart is a child of that main gameobject. I tried checking for each bodypart if it’s hit, and then decrease the health by an appropriate amount. My current code is:
public class AI_N_hitscan : MonoBehaviour {
public int hitPoints;
public Transform leftLeg;
public Transform rightLeg;
private void LateUpdate()
{
if (hitPoints <= 0)
{
Debug.Log("he died");
}
}
For the main system, and
public class arm : MonoBehaviour {
public GameObject main;
void OnTriggerEnter(Collider bullet)
{
if (bullet.gameObject.CompareTag("Bullet"))
{
main.GetComponent<AI_N_hitscan>().hitPoints = main.GetComponent<AI_N_hitscan>().hitPoints - 1;
}
}
for each limb (in this case the arm). However, since the separate limbs aren’t rigidbodies (only the main part is one, to prevent the bodyparts from falling off and such), I need to have “istrigger” checked for them. The issue is that the rigidbody will then ignore those bodyparts and fall through the ground. Does anyone have a way of fixing this issue? I’ve thought about adding a second body, which is comprised only of triggers, and not having the main body be triggers, but that probably isn’t very performance-friendly