Okay so I have a 2D platformer and when my character jumps from one platform to another I witness a strange effect.
When he jumps and I still have the jump button held down, as he is making contact with the platforms Collider, the OnCollisionEnter2D method doesn’t get called, all the time.
Instead there are these sweet spots where continually holding down the jump button allows my character to immediately jump up off the platform the second it makes contact. Thus not calling the collision method.
It’s only when I apply a slight change in my characters horizontal movement while jumping, or come to rest on the platform, that the collision is detected.
What I am not understanding is, since my character is able to jump on the surface of my platforms then obviouslty my character has made contact with the platform. So why is it the OnCollisionEnter2D does not get called every single time, that occurs?
Two possible reasons come immediately to mind: First, that you’re allowing the jump before contact occurs, second, that the jump is disengaging contact before the OnCollisionEnter2D is called, thereby preventing it from getting called. Just speculation, though, since you didn’t post any code.
Assuming you’re correct about the jump disengaging contact before the OnCollisionEnter2D is called, what can I do to circumvent this?
The platform is an endless runner in the vertical direction and in my OnCollisionEnter2D method, depending on which platform my character is colliding with, it will rearrange the platforms my character has yet to collide with.
You check if the player is grounded and allow him to jump again in the Update, using your groundCheck GameObject, maybe (almost 100% sure) your groundCheck hits the ground before the collider and allow the player to jump again before the contact occur.
Try to move your groundCheck up a little.
Thanks, but I tried this as well and it doesn’t even allow me to jump or move laterally.
My problem is pretty simple to check btw. Just make a new scene with one platform and have a cube jump up and down. And have a debug.log(coll.gameobject), in your OnCollisionEnter2D. You will see it doesn’t get called 100% of the time. Not sure why.