- Home /
can stop character form double jumping
can't get character to only jump once new to scripting the point of the script was for him to jump then reset jump to 0 so he couldn't jump twice in the air but it only resets one time the character has rigidbody on with continuous dynamic and a capsule Collider and the ground has a terrain collider i just cant get the script to tell when he in the air reset jump to 0. i ran a debug log it tells everytime he hits gound it just wont detect when he in the air been up hour trying to figure it out
please help
public var jump:float=0;
public var jumpheight :float=20;
function Update ()
{ if (Input.GetKeyDown (KeyCode.Space)) {transform.Translate(Vector3.up (jump) Time.deltaTime, Space.World);}}
function OnCollisionStay(collision : Collision){
if (( collision.gameObject.tag==("Ground") ))
{(jump)=(jumpheight);}
else {(jump)=(jump);}
Please format your code correctly. It will make helping you much easier.
Either use:
Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Space)
or write some code that waits before he jumps again. Basically what is happening is multiple update calls are occurring before your OnCollisionStay is changing your jump var.
thanks just started learning 2 days ago didnt know what was going on
Rather than checking if the players collider is touching the floor, I would use a raycast to check the height of the floor before the player jumps, then each time the player tries to jump, check to make sure their current height isn't greater than the initial jumping height.
An example of how of I mean (second example): http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
Answer by rasheedqw · Aug 05, 2013 at 02:33 AM
https://www.youtube.com/watch?v=y0tAImhbjIQ
the answer to how to stop a character from double jumping in the air is here
What if that link is lost or disabled in the future? Posting links without answers is not helpful. At the very least you could have given us the time index of the answer as the video is 38 $$anonymous$$utes long.