- Home /
How to Stop Continuous Collision with GameObject
When i hit EnemyObject with Arrow to decrease health by 50, but i happens 50+50 = 100 at one shot, So enemy die at single shot already i have selected rigidbody collision detection is Discrete, but two or more times collided each other to decrease health, how to solve this problem, here is the Code... public void OnCollisionEnter(Collision others) {
if (others.gameObject.tag == "Arrow") {
EnemyHealth = EnemyHealth - 50;
EnemyHurt.Play ("hurt");
Debug.Log ("EnemyHealth :" + EnemyHealth);
}
I need only decrease 50 only once but EnemyHealth is decreases two or more times..Please solve this problem
Answer by Blablolog · Aug 17, 2015 at 05:45 PM
usually projectile tells object that it was just attacked.
So on HealthAndDamage script attached to attacked object in Update you have this
if (justAttacked == true && hitByArrow) { EnemyHealth = EnemyHealth - 50; EnemyHurt.Play ("hurt");
Debug.Log ("EnemyHealth :" + EnemyHealth); justAttacked =false; }
on arrow you have this code
if (hit.transform.tag == enemyTag )
{
HealthAndDamage HDScript = hit.transform.GetComponent(); HDScript.iWasJustAttacked = true;
}
Your answer

Follow this Question
Related Questions
Collision with Plane fails 0 Answers
Is their a way to change boxcollider2d's method of detection? 1 Answer
Check If Any Objects In Your Game Are Colliding? 1 Answer
Mesh Colliders and 2D Colliders 1 Answer
Help! OnTriggerStay() not working!!! 0 Answers