- Home /
Jump same amount, no matter how long jump key is held
Hello, i would like to know how to make it so that, even in you hold down the space/ up key for any amount of time, the jump is always the same height, because at the moment if i were to hold down the space/up key for say 5 seconds, the object would never fall, and my game depends on the object jumping and falling the same height on every jump. Thanks
My Jump Code:
using UnityEngine; using System.Collections;
public class Jumping : MonoBehaviour {
// Player Jump
public int jumpHeight;
// Update is called once per frame
void Update () {
// Left Control
if (Input.GetKey("up")){
rigidbody.AddForce(new Vector3(0, jumpHeight,0), ForceMode.Force);
}
}
}
Answer by TheFloatingSheep · Jan 30, 2015 at 05:53 PM
You can use the isGrounded variable of the character controller, so the player can jump just after he fall on the ground.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded)
print("We are grounded");
}
}
Thank you for the reply, but i sorry i forgot to say that, i have not got any ground, my character is always suspended and i just want the jumps to all be equal. I had an idea involving having a slight delay after the fisrt jump has happened so that the second jump would start from the velocity of 0 again. I hope i make sense, and thanks for your reply