- Home /
Double Jump
Hello Unity3D i have a problem with making my characters double jump.The problem is whenever i try to make my character double jump,At the start of the game the characters fall through the arena instead of double jumping.Is it because of the gravity or is it because i have to make a separate script in order for my characters to double jump?If anyone knows how i can fix this problem.Can you please tell me how?I have been stuck on this for a week....
#pragma strict
var Run:AudioClip;
var rotationSpeed : float = 10;
var walkSpeed : float = 7;
var gravity : int = 50;
var body : Transform;
audio.volume = 0;
private var double_jump : boolean = true;
private var yRot: float;
private var moveDirection : Vector3 = Vector3.zero;
function Update () {
var Controller : CharacterController = GetComponent(CharacterController);
var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
var height : Vector3 = transform.TransformDirection(Vector3.up);
var horizontal2: Vector3 = transform.TransformDirection(Vector3.left);
if (Controller.isGrounded)
double_jump = true;{
if(Input.GetKeyDown("space")){
moveDirection.y -= gravity * Time.deltaTime;
animation.Play("Jump");
Jump();
}
if(Input.GetAxis("Vertical")||Input.GetAxis("Horizontal")){
if (!animation.IsPlaying("Jump"))
if (!animation.IsPlaying("Jump"))
if(!animation.IsPlaying("Kick1"))
if(!animation.IsPlaying("Sword_5"))
if(!animation.IsPlaying("Sword_6"))
if(!animation.IsPlaying("Sword_7"))
if(!animation.IsPlaying("Sword_8"))
if(!animation.IsPlaying("Spinning_Slashes"))
animation.CrossFade("Run2");
animation["Run2"].speed = walkSpeed/100;
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
audio.Play();
}else{
if (!animation.IsPlaying("Jump"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_5"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_6"))
if(!animation.IsPlaying("Overhead_slash4"))
if(!animation.IsPlaying("Overhead_slash3"))
if(!animation.IsPlaying("Violets_Pause_2"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_1"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_2"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_3"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_4"))
if(!animation.IsPlaying("punch1"))
if(!animation.IsPlaying("punch2"))
if(!animation.IsPlaying("punch3"))
if(!animation.IsPlaying("punch4"))
if(!animation.IsPlaying("punch5"))
if(!animation.IsPlaying("Berserk"))
if(!animation.IsPlaying("Teleport"))
if(!animation.IsPlaying("Snake_"))
if(!animation.IsPlaying("Snake__2"))
if(!animation.IsPlaying("Snake__3"))
if(!animation.IsPlaying("Snake__4"))
if(!animation.IsPlaying("Snake__Launcher"))
if(!animation.IsPlaying("Juggle_Launcher_Ground"))
if(!animation.IsPlaying("invisibility"))
if(!animation.IsPlaying("Violet_Poison_Dagger_Throw"))
if(!animation.IsPlaying("Demonic_Wave"))
if(!animation.IsPlaying("Slash_Combo"))
if(!animation.IsPlaying("Slash_Combo_2"))
if(!animation.IsPlaying("Rex_Pause"))
if(!animation.IsPlaying("Escalibur"))
if(!animation.IsPlaying("Invisibility"))
if(!animation.IsPlaying("Rex_Sword_Combo"))
animation.CrossFade("Stance");
else{
if (Input.GetButtonDown("space"))
{
moveDirection.y -= gravity * Time.deltaTime;
double_jump = false;
}
}
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
audio.Play();
}
if(Input.GetAxis("Vertical")){
yRot += 10* Input.GetAxis("vertical");
}
}
}
function LateUpdate(){
// Rotate the Character to match the direction he/she is going
if(Input.GetAxis("Vertical") == 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = 90;//Right sideways running
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = 270;//Left sideways running
}
}else if(Input.GetAxis("Vertical") > 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = -270;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = -90;
}
}else if(Input.GetAxis("Vertical") < 0){
if(Input.GetAxis("Horizontal") == 0){
body.localEulerAngles.y = -180;
}else if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = -180;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = -180;
}
}
}
function Jump(){
gravity = 30;
yield WaitForSeconds(0.2);
gravity = -50;
}
Have you checked out how other users have solved their character's double jumps? Such as http://answers.unity3d.com/questions/topics/double+jump.html
Answer by Kamuiyshirou · Jan 05, 2015 at 04:45 PM
You have to decide only one way out: double jump or jump. Because you can not generate two events in a single output ( keyboard or touch) . I advise you to make an "add -jump " , see this question answered , but is in C # :
http://answers.unity3d.com/questions/697972/how-can-i-my-wall-jump.html
OH....So your saying that i need to get rid of this
if (Controller.isGrounded)
double_jump = true;{
if(Input.Get$$anonymous$$eyDown("space")){
moveDirection.y -= gravity * Time.deltaTime;
animation.Play("Jump");
Jump();
}
and use this?
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.Space) && isGrounded ){
jump = true;
}