- Home /
Rigidbodies touching but OnCollisionStay stops being called
I want to simulate two pistons that replicates the behaviour of a balance. I'm doing this with spring joints and applying the inverse weight one another when OnCollisionStay is called. This are my pistons and their rigidbodies and joints. Are exactly the same on both. This is my SpringForceTransmisor.cs code: using UnityEngine;
public Rigidbody InverseJoint;
private void OnCollisionEnter(Collision collision) {
Debug.Log("Enter");
}
private void OnCollisionExit(Collision collision) {
Debug.Log("Exit");
}
private void OnCollisionStay(Collision collision) {
InverseJoint.AddForce(-(collision.rigidbody.mass * Physics.gravity));
Debug.Log("Stay");
}
And this is a video of what's happening.
So, according to the log showed on the video, OnCollisionStay() stops being called even if OnCollisionExit() had never been called. How is this possible? I've always thought that OnCollisionStay() is called every frame from OnCollisionEnter frame and OnCollisionExit frame.
Can anyone shed some light about what's going on here?
Check if your rigidbody is sleeping?
https://docs.unity3d.com/ScriptReference/Rigidbody.IsSleeping.html
Answer by aurelioprovedo · Oct 31, 2017 at 05:56 PM
The docs say Collision stay events are not sent for sleeping Rigidbodies.
You can try setting your rigidbodies' sleepThreshold to a very low value.
However, I would advice you to not use OnCollisionStay for this. It is good for performance that rigidbodies can sleep. If I were you, I would store the collision state in a private boolean, and then do the work in FixedUpdate.
Your answer
Follow this Question
Related Questions
collisions not working 1 Answer
Restrict the rigidbody to be affected by only 1 joint 0 Answers
Bounce back after spinning an object once it hits the angle limit. 1 Answer
Mesh Collider colliding with Primitives is jittery 1 Answer
Character pushes a cart. How to prevent cart from clipping? 0 Answers