If i spam the jump button (w) my ball jumps the first time then when it lands it does not jump right away but it jumps randomly after a number of button presses.
#pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
private var isFalling = false;
function Update ()
{
//Handle ball rotation.
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);
if (Input.GetKeyDown(KeyCode.W) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}
function OnCollisionStay ()
{
isFalling = false;
}
I head this was a arithmetic behavior problem in java script so i tried in c# but its not working.
you are calling the collision function incorrectly… there isn’t a unity engine function called “OnCollisionStay” that takes no arguments.
It always needs to have the argument of type collision.
What you have done here is overload the unity engine function with your own definition (i.e. one without parameters) but the unity engine is never going to call that. What you want to do is override the unity engine function with your own code.
The code was given to me by someone else. I have very little experience programming. I’m understanding the concept of what your saying but i have no idea how to put it into code.