CodexBloom - Programming Q&A Platform

Unity 2023.1: Unexpected Jumping Behavior When Using Rigidbody with Continuous Collision Detection

👀 Views: 205 💬 Answers: 1 📅 Created: 2025-07-17
unity rigidbody 2d physics jump C#

I'm working on a 2D platformer in Unity 2023.1 and I’m experiencing some unexpected jumping behavior with my player character. My player uses a `Rigidbody2D` component and I have set the collision detection to `Continuous`. However, the character sometimes gets exploring to the ground and doesn’t jump, even when the jump input is held. Here’s the code I’m using to handle jumping: ```csharp public class PlayerController : MonoBehaviour { public float jumpForce = 5f; private Rigidbody2D rb; private bool isGrounded; private void Start() { rb = GetComponent<Rigidbody2D>(); } private void Update() { if (Input.GetButtonDown("Jump") && isGrounded) { Jump(); } } private void Jump() { rb.velocity = new Vector2(rb.velocity.x, jumpForce); } private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Ground")) { isGrounded = true; } } private void OnCollisionExit2D(Collision2D collision) { if (collision.gameObject.CompareTag("Ground")) { isGrounded = false; } } } ``` I’ve confirmed that the ground objects have the `Ground` tag and appropriate colliders. I’ve also tried adjusting the `Rigidbody2D` settings like the drag and mass, but the scenario continues. The character sometimes ignores the jump input, especially after landing from a jump or moving quickly. I also noticed that the `OnCollisionEnter2D` is firing correctly, as `isGrounded` seems to toggle as expected, yet the jump still fails intermittently. I have logging in place to check the value of `isGrounded`, and I see that it remains `true` when it shouldn't be. I suspect it might be an scenario with the physics calculations when switching to `Continuous` collision detection, but I'm not sure how to troubleshoot this further. Any insights or suggestions on how to resolve this jumping scenario would be greatly appreciated!