2
\$\begingroup\$

I'm currently trying to build a simple demo where the player can jump. This is the script I have setup so far.

using UnityEngine;
using System.Collections;

public class PlayerJump : MonoBehaviour
{
    public Vector3 jumpForce;

    void OnCollisionStay (Collision other)
    {
        print("OnCollisionStay");
        if (Input.GetKey (KeyCode.Space) && other.gameObject.tag == "Block")
        {
            rigidbody.velocity += jumpForce;
        }
    }
}

Whenever I check the console, the message "OnCollisionStay" is only printed 21 times. Just for more details the GameObject this script is attached to contains a rigidbody that uses gravity, has the x, y, and z rotation axes frozen, and the z position axis forzen as well. The gameObject I'm trying to collide with has a simple box collider attached to a cube with a scale of (5, 1, 5). What am I doing wrong? I am under the impression that OnCollisionStay continuously executes until the player is no longer colliding with anything, then starts executing again on collision?

\$\endgroup\$
2
\$\begingroup\$

This sounds like the object is at rest and the Rigidbody has been put to sleep.

You can modify Rigidbody.sleepThreshold to change this behaviour for a single instance.

Alternatively you can change the threshold project wide via the Physics Manager. Try setting "Sleep Threshold"/"Sleep Velocity" to zero.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.