- Home /
How to disable flying ?
My player is rigidbody , so i use this script ( C# ) for jumping
public float jacinaSkoka = 1600;
if( Input.GetKeyDown("space"))
{
rigidbody.AddForce(Vector3.up * jacinaSkoka);
}
if someone press space rapidly player start flying . i want , if someone press space 2, 3, 4 times in a given time interval, for example 0.6 seconds, to player jumps only once.
Thanks in advance. :D
Comment
Answer by Piflik · Jun 06, 2012 at 10:42 PM
You could set a timer and increment it every frame. Then test against it to jump.
public float jacinaSkoka = 1600f;
private float jumpTimer = 0f;
private float timeToJump = 0.6f;
private void Update(){
if(Input.GetKeyDown("space") && jumpTimer > timeToJump) {
rigidbody.AddForce(Vector3.up * jacinaSkoka);
jmpTimer = 0f;
}
jumpTimer += Time.deltaTime;
}
(Don't really know C#, yet, so I don't know if this works ;))
Your answer
Follow this Question
Related Questions
Freeze rigidbody position in script 5 Answers
Custom Controller 1 Answer
how to Apply Gravity at Run time ..????????? 2 Answers
Collision If Statement And Falling throught the ground (2 questions) 1 Answer
rotation problem 1 Answer