- Home /
bullet damage problem
I wrote a collision and bullet damage script, bullet is tagged as bullet and both are rigid bodies plus both triggers are checked so i can't figure out why it isn't working?
using UnityEngine; using System.Collections;
public class BulletDamage : MonoBehaviour {
public int HEALTH=100;
public GameObject bullet;
static public int bulletDamage = 25;
public GameObject clavicle;
public GameObject soldier;
void OnTriggerEnter(Collider other)
{
if(other.tag == "bullet");
{
HEALTH = HEALTH - bulletDamage;
}
if (HEALTH<=0)
{
clavicle.transform.parent = soldier.transform;
animation.Play("soldierDieFront");
}
}
}
Add to your OnTriggerEnter line of
Debug.Log(other.name + " " + other.collider);
basically prove that what you are expecting to hit the trigger is
Do you mean that Health is not being decremented by 25? As getyour411 suggested, Debug to see if you are entering the if statement.
if(other.tag == "bullet");
{
Debug.Log("HEALTH before decrement: " + HEALTH );
HEALTH = HEALTH - bulletDamage;
Debug.Log("new HEALTH value: " + HEALTH );
}
for example, smth like this, you can see the old and new value of health, if you dont see any printed line in the console, then the problem is with the tag, maybe you have not assigned.
Answer by HappyMoo · Jan 22, 2014 at 05:22 PM
if Both are rigid Bodies and moved by physics, they don't trigger each other, but collide.
See this to understand: http://www.youtube.com/watch?v=WFkbqdo2OI4
Also, for fast moving bullets, what you're trying to do isn't ideal either, because the bullet could miss the body or you need to step up the simulation precision. I'd recommend to use raycasts to find out where you hit
Your answer
Follow this Question
Related Questions
Health and Damage [C#] 2 Answers
Take health from enemy 3 Answers
Instantiate on value change 2 Answers
Distribute terrain in zones 3 Answers