Collision detector suddenly stops detecting collision when move the player! Bug?
Hello my friends. I'm with a problem that i can't fix. I'm working in a 2D platform game for Android (same style as Super Mario), and when i walk backward with the Player (to the left), the OnCollisionEnter2D disable, making it impossible to jump with the Player, because jump is only available when he's grounded.
Some observation: -"Pato" is the tag of the player -"public void pulo()" is called when i touch the screen button on a phone
Here's the code (C#)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Jump : MonoBehaviour { public float thrust =210; public Rigidbody2D rb; public bool grounded; void Start () { rb = GetComponent<Rigidbody2D>(); } //Is grounded void OnCollisionEnter2D(Collision2D collision) { if (gameObject.tag == "Pato"){ grounded = true; } } //Isn't grounded void OnCollisionExit2D(Collision2D collision) { if ((gameObject.tag == "Pato")) { grounded = false; } } //To jump public void pulo(){ if (grounded == true) { rb.AddForce(transform.up * thrust); } } }
Thank you for your time!