- Home /
Character won't jump script help.
I have followed a tutorial to the letter and while my character moves in a 2d planes like I want it doesn't seem to jump. I have the script here but can't figure out what went wrong.
Jump Script
#pragma strict
var dt : double;
var jumpButton: String;
var jumpDelay : float;
var jumpForce : double;
var canJump: boolean;
var timeSinceLastJump: float;
var base : GroundDetection;
var movement : LateralMovement;
function Start () {
dt = Time.deltaTime;
jumpButton = "Jump";
jumpForce = 6;
jumpDelay = 2.5;
canJump = false;
timeSinceLastJump = 10;
base = gameObject.GetComponentInChildren(GroundDetection);
movement = gameObject.GetComponent(LateralMovement);
}
function Update () {
timeSinceLastJump += dt;
if(base.onGround){
movement.SetSuspension(false);
if(timeSinceLastJump > jumpDelay){
canJump = true;
}
else if (!AirControl()){
movement.SetSuspension(true);
if(canJump && Input.GetButton(jumpButton)){
rigidbody.velocity.y += jumpForce;
canJump = false;
timeSinceLastJump = 0;
}
}
}
}
function AirControl(){
return rigidbody.velocity.y > 0;
}
Comment
Best Answer
Answer by Scribe · Aug 18, 2014 at 08:55 AM
Your problem is line 45 else if (!AirControl()){
If you are able to jump timeSinceLastJump > jumpDelay
will return true, and so the else will never be called.
Getting rid of the else should solve your problem!
Your answer
Follow this Question
Related Questions
Drag Object Via Axis Handles 0 Answers
how can i manually update unity web player ? 0 Answers
Raycast shooting in the middle of the screen 0 Answers
How to add to a 3D object's length through code? 1 Answer
Applying a texture to a sphere 1 Answer