- Home /
Enemy Health Problem
I have a script on my bullet prefab that when it collides with something that has a tag of enemy it destroys it and itself which works fine when my bullet is travelling at about 20mph but when I change it to the actual speed of an bullet it dosent destroy anything and looks like it just goes straight through it, can anyone help me with this?
Answer by swisscoder · Oct 31, 2011 at 04:48 PM
actual speed of a bullet is propaply to fast to trigger the OnEnter/OnExit, when your collider is very small (collider of the bullet).
A way to work around that could be to raycast in shooting direction, at the moment you shoot. To see if you hit the enemy, and then do the damage to the enemy. In case you apply gravity to the bullet, this might not be a good solution, if you can shoot over a longer distance in your game.
But sure you can find more information in the net, it's a problem that comes up quite often.
Answer by ninjarob · Oct 30, 2011 at 09:02 PM
Not sure why its not working without seeing more of the project but suggest replaceing the bullet code with this
var damage:int = 1;
function OnCollisionEnter(myCol: Collision){
myCol.gameObject.SendMessage("Damage",damage,SendMessageOptions.DontRequireReceiver);
}
also put a print in the damage function to see if the message is makeing it to the target
Your answer
Follow this Question
Related Questions
Apply Damage To Player On Collison With Specific Game Object 1 Answer
Deduct health on collision 2 Answers
Destroying Enemy Help 5 Answers
Destroy Scripting Help 1 Answer
How to create Enemy Health Bar ? 4 Answers