- Home /
OnCollisionEnter/Stay not working when jumping on Enemy
Hi all!
I'd like to know if anyone knows why my collisions (on enemy) stops detecting my player when i jump on it (and stay there)
So the case is:
Player:
2d-SpriteRenderer
CharacterController
2 Scripts - 1 controls movement, another lifebars
Enemy:
2d-SpriteRenderer
Rigidbody
Sphere collider (As collider, physics purpose)
Sphere collider (As trigger, enemy "Aggro" zone)
So, when i move Player and enter "aggro" zone, enemy comes to me. When both collide (It's working) my healthbar get's down, but...
If i jump on the enemy, the player just stand here, on the enemy (so there are some sort of collision) but OnCollisionEnter && OnCollisionStay just don't work.
¿Anyone solved something like this?
I'll attach some screenshots ...
OnCollisionEnter/Stay working - My health goes down.
When i stay ON the enemy, OnCollisionEnter/Stay stops working - My health isn't moving anymore..
The code in the Enemy script for collision...
void OnCollisionStay(UnityEngine.Collision other){
if (other.gameObject.tag == "Player") {
GameObject player = GameObject.FindGameObjectWithTag ("healthBar");
barraVida playerScript = player.GetComponent<barraVida> ();
playerScript.health -= 3;
Debug.Log ("STAY"+playerScript.health);
}
}
Thanks all !!! :)