- Home /
How to disable flying?
my player is rigidbody , so i use this script ( c# ) for jumping . Problem is if someone press space 2 , 3, 4 ,5 times player start "flying"
Script:
Blockquote
public float jacinaSkoka = 1600;
if( Input.GetKeyDown("space")) { rigidbody.AddForce(Vector3.up * jacinaSkoka); }
Blockquote
i want , if someone press space 2, 3, 4 times in a given time interval, for example, 0.6 seconds, the player jumps only once
You could check if player is grounded and if so: you can jump, else not. You could check for a collision between player and ground for this.
Answer by bormeth · Jul 22, 2012 at 09:31 PM
Hey m8 :) Had same problem.. Here is what i did
if ((Input.GetKeyDown("space") || Input.GetKeyDown("up") || Input.GetKeyDown("w")) && Physics.Raycast(transform.position, Vector3.down, 1.0f)) { rigidbody.AddForce(Vector3.up * playerJumpSpeed, ForceMode.Impulse); }