- Home /
Question by
Jackop222 · Nov 13, 2013 at 04:51 PM ·
2dmovement scriptjumping
How to stop spam jumping?
I have a basic 2d movement script, but the only problem is you can spam the space bar and fly, is it possible to stop this?
#pragma strict
var movespeed : float =6.0f;
var jumpspeed : float = 200f;
var gravity : float = 1f;
var jumpSpeed : float = 100f;
function Start () {
timer1 = 0;
}
function Update () {
if(Input.GetKey(KeyCode.A)){
transform.Translate(Vector3.left * movespeed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.D)){
transform.Translate(Vector3.right * movespeed * Time.deltaTime);
}
if (Input.GetKeyDown(KeyCode.Space)) {
rigidbody.AddRelativeForce(0, jumpSpeed, 0);
timer1 = 10;
}
}
Comment
Answer by Dracorat · Nov 13, 2013 at 04:56 PM
You should do a very short distance raycast from the bottom of the sprite's feet and see if it collides with something. If that something is something you could jump from (like terrain) then apply the force. Otherwise do nothing.
If you're not using physics, then instead of raycasting just compare the position of nearby objects for the same.
Sorry i didnt mean like that, i want some sort of timer to wait before you can jump again?
Your answer
