Problem with OnCollisionStay and user input

Hi

I have this code where I want to give force to ball if it rest on a box and user press space. It works if I press space before ball hits the box, but if ball rest on box and I press space nothing happens.

This is script in box gameobject:

function OnCollisionStay (collision : Collision) {
for (var contact : ContactPoint in collision.contacts) {			          				
		if (Input.GetButton ("Space")) {			 	
		 	contact.otherCollider.rigidbody.AddForce( -contact.normal * Force, ForceMode.Impulse);
 }

}

if ball rest on box and I press space nothing happens

Probably the first thing I’d check is this: is OnCollisionStay() still being called in that circumstance? Easiest way to check this is with Debug.Log().

If it is, then you know something in your own function isn’t working as expected.

If it isn’t, then you know that hook won’t work for you, and you’ll need to make a more substantial change, either with your collision setup or with the way you check if the ball is “on” the box.

Problem was that rigidbody of ball falls asleep, and collision is no longer detected.

this is code I get to work:`var bumperForce : float = 100;
var shoot:boolean = false;
var lastCollision : GameObject;
var normal : Vector3; 

function FixedUpdate () {
	if (Input.GetButton ("Space") & shoot) {
		lastCollision.rigidbody.AddForce( normal * bumperForce,  ForceMode.Impulse);
		shoot = false;
	} 
} 

function OnCollisionEnter(collision : Collision) {
	lastCollision = collision.gameObject;
    for (var contact : ContactPoint in collision.contacts) {
			shoot = true;
			normal = -contact.normal;
    }
} `