In my project, I have a player object placed a few pixels above a ground object, and they all have colliders enabled, and they worked well. The player will fall down, and when it collides with the ground, the player can jump. The problem is if I leave the player for a while until the player stops bouncing after falling down from the sky, it will not collide with the ground anymore, thus triggering the OnCollisionExit2D function. This results in the player can’t jump, even though on my screen, it is as if the player is still touching the ground. Did I miss something? Any help will be appreciated, thanks!
Additional info:
The player object has Rigidbody 2D with dynamic body type and circle collider 2D.
The ground object has Rigidbody 2D with kinematic body type and box collider 2D.
Hi, I tried setting the objects’ Rigidbody 2D’s collision detection to continuous and their sleeping mode to never sleep, it still doesn’t work. Any other ideas?
The physics system won’t do this, there’s no setting to stop it. It’s something you’re doing in your scripts. You’ll get an “exit” callback when it’s no longer in contact; that’s all that can be said.
Sleeping won’t stop contacts nor would continuous col-det.
Hi, thanks for the reply. Currently, I’m not sure why is the objects not colliding after a while. The scenario is the player object falls from the sky to the ground (using default gravity). For the first few seconds, the player collides with the ground, however after a few seconds (after the player stops bouncing), the player no longer collides with the ground. Regarding collision, currently my script is only setting a boolean variable called canJump and codes for logging/debugging. Just wanted to confirm if this is a default behaviour, if an object has touched the ground and it no longer moves, will the ground push the object back until it is no longer colliding with the ground? I’m not really sure about this problem, thanks!
Please show this because we cannot debug your scripts here and we cannot be sure on what you actually mean by “stops colliding”. You’re describing something that takes 10 seconds to set-up and works perfectly so there’s something else going on here that you’ve done.
First of all, I just wanted to mention that I used a very basic approach to collision detection (I am only using 2 Collider 2D Objects, overdependent on them), and only recently found out about CapsuleCast, I think I will try that in the future.
For now, so here’s the first part of the scene (the player just fell from the sky):
Here’s the script:
Then, here’s a few seconds after that:
Keep in mind that the player is colored black because of my script: