I have always assumed that OnCollisionStay would fire always in conjunction with OnCollisionEnter.
However, it doesn’t appear to be the case.
Here, depending on the bounce combine method on the Sphere’s physics material. OnCollisionEnter will fire if it’s set to Minimum. When Maximum, the event doesn’t fire.
Using Unity 2021.3.0
Script added to Sphere:
public class CollisionEvents : MonoBehaviour {
private int fixedFrames;
private void FixedUpdate() {
fixedFrames++;
if (Input.GetMouseButton(0) && Time.frameCount > 100) {
GetComponent<Rigidbody>().AddForce(Vector3.up * Random.Range(1f, 2f), ForceMode.Impulse);
}
}
private void OnCollisionEnter(Collision collision) {
GetComponent<Rigidbody>().velocity = new Vector3(collision.relativeVelocity.x, collision.relativeVelocity.y);
Debug.Log("<color=red>Collision ENTER " + fixedFrames + "</color>");
}
private void OnCollisionStay(Collision collision) {
Debug.Log("<color=green>Collision STAY " + fixedFrames + "</color>");
}
private void OnCollisionExit(Collision collision) {
Debug.Log("<color=yellow>Collision EXIT " + fixedFrames + "</color>");
}
}
Sphere setup:
Is this a Bug? Shouldn’t OnCollisionStay always fire immediately after OnCollisionEnter?