Unity 2023 - Rigidbody configuration guide to AddForce in FixedUpdate when using Continuous Collision Detection
I'm reviewing some code and I'm working on a 2D platformer in Unity 2023, and I've encountered a frustrating scenario with my Rigidbody's physics behavior. I have a player character set up with a Rigidbody2D component, and I'm trying to implement a jump mechanic using the AddForce method. However, the character only jumps occasionally, even when the conditions are met. Here is my code snippet where I'm handling the jump input: ```csharp void Update() { if (Input.GetButtonDown("Jump") && isGrounded) { Jump(); } } void Jump() { rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse); } ``` I have also set the Rigidbody2D to Continuous Collision Detection in the inspector because I realized that my player was passing through platforms occasionally. While this improved collision handling, it seems to have introduced this jump scenario. I checked the console for any warnings or errors, but there are none. I've tried adjusting the jumpForce value and verified that the isGrounded check works correctly by logging whenever the player is grounded. Additionally, I ensured that my physics settings are correctly configured with the default gravity scale. Here's a simplified version of my `isGrounded` check: ```csharp private void OnCollisionStay2D(Collision2D collision) { if (collision.gameObject.CompareTag("Ground")) { isGrounded = true; } } private void OnCollisionExit2D(Collision2D collision) { if (collision.gameObject.CompareTag("Ground")) { isGrounded = false; } } ``` Despite these checks and configurations, the jump only works about 50% of the time. I also experimented by switching the Rigidbody2D to Discrete Collision Detection, but that caused the character to fall through platforms again. Does anyone have insights into why the jump may not be registering consistently with Continuous Collision Detection? Are there any best practices to follow in this scenario that I'm missing? Thanks for your help! This issue appeared after updating to Csharp 3.9. I'm working in a Debian environment.