- Home /
Can't get onCollisionStay() to work for me
I'm trying to get a ball to be able to jump, but when it jumps and lands again it isn't able to jump a second time, probably due to my misuse of the function onCollisionStay()? Though I'm unsure of what is wrong with my code.
This is what I have
function Start () {
GetComponent.<Rigidbody>().drag = 2;
}
private var isFalling = false;
var jumpHeight = 8;
function Update () {
var ballRotationX : float = Input.GetAxis ("Horizontal") * 20;
var ballRotationZ : float = Input.GetAxis ("Vertical") * 20;
GetComponent.<Rigidbody>().AddForce(ballRotationX, 0.0f, ballRotationZ);
if (Input.GetButtonDown("Jump") && (isFalling == false)) {
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
isFalling = true;
}
}
function onCollideStay() {
isFalling = false;
}
Answer by Landern · Mar 23, 2015 at 01:27 PM
"onCollideStay" isn't a unity recognized function that will be called as part of the Component design, you can call it manually of course like any function you declare, but it will not get called or invoked like you think by Unity automagically.
The current problem (i say this assuming you will have others, perhaps not) is that you are not using the correct function name of: "OnCollisionStay"
it would look like:
function OnCollisionStay(collisionInfo : Collision) {
isFalling = false;
}
Answer by ma22be61 · Mar 23, 2015 at 08:48 PM
Because onCollideStay is not a Unity function. This is the right code :
function OnCollisionStay(collisionInfo:Collision)
{
isFalling = false;
}