- Home /
Irregular jumping
Hi I'm trying to get my gameobject to jump by adding a force only when it touches the ground which works fine when I use Input.GetButtonDown
but when I use Input.GetButton
the jump is irregular (Randomly it seems), I thought maybe force was applying more than once if I keep the button pressed, but I if I put a bool to control that the same thing happens, any ideas?
Here is my code:
void Update () {
if (Cubo!=null){
transform.Translate(Vector3.right*moveright);
if (suelo & Input.GetButton("Fire1")
& fuerza){
Cubo.transform.rigidbody.AddForce(transform.up*jump*10*(Time.fixedDeltaTime));
fuerza=false;
}
else{
Cubo.transform.rigidbody.AddForce(transform.up*(-jump*.85f)*Time.fixedDeltaTime);
fuerza=true;
}
}
}
void OnTriggerEnter (Collider other) {
suelo=true;
}
void OnTriggerExit (Collider other) {
suelo=false;
}
Here is a short video demo of what happens
In the video I show first what happens with Input.GetButtonDown, then I change the code to Input.GetButton to show the difference and I click as fast as I can to make the same effect
Answer by Stormizin · Jul 24, 2014 at 09:15 PM
Input.GetButton: Returns true while the virtual button identified by buttonName is held down.
Input.GetButtonDown: Returns true during the frame the user pressed down the virtual button identified by buttonName.
I know that but I restricted the Input.GetButton to only act once when the game object touches the ground and still does the same, I also tried to use forcetype.impulse but it throws the object flying in the air
I've tried this now and it doesn't, I may have not tested it correctly my bad do you think this restraint would work? Is so how would you implement this? Thank you
Your answer
![](https://koobas.hobune.stream/wayback/20220613154922im_/https://answers.unity.com/themes/thub/images/avi.jpg)