Hello, I’ve got AI that looks shoots at the player(using objects for now). When the player is hit, it decreases his health by 1, but for some reason only when the player is moving(when the arrow/WASD keys are pressed).
Here’s the code I’m using for the colliding:
invTimer = invTime;
gui.GetComponent("HUD").Damage(1);
Destroy(other.gameObject);
bloodEmitter.emit = true;
yield WaitForSeconds(.1);
bloodEmitter.emit = false;
That’s inside a switch statement checking the tag of the colliding object.
It damages the player, destroys the bullet, and emits some particles(blood). But it only does it while the player is moving. I’ve put a print statement at the top and it prints “Hit”, but only if the object is moving.
What’s wrong here?
P.S. It’s not that the bullet is moving to fast, because it moves pretty slow actually.
EDIT: Here’s the complete switch statement.
function OnTriggerEnter(other : Collider){
if (invTimer == 0){
switch(other.tag){
case "HOrb":
if(gui.GetComponent("HUD").hp != gui.GetComponent("HUD").maxHp){Destroy(other.gameObject);};
gui.GetComponent("HUD").Heal(2);
break;
case "Bullet":
invTimer = invTime;
gui.GetComponent("HUD").Damage(1);
Destroy(other.gameObject);
bloodEmitter.emit = true;
yield WaitForSeconds(.1);
bloodEmitter.emit = false;
break;
}
}
}
Check this out: http://unity3d.com/support/documentation/Components/RigidbodySleeping.html Your rigidbody might have gone to sleep...
– GuyTidhar