Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · Jan 05, 2015 at 04:31 PM · javascriptgravityjumping

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;
 }
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SaraCecilia · Jan 05, 2015 at 04:43 PM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image IKilledKenny_2 · Jan 06, 2015 at 04:09 AM 0
Share

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;
          }

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change the gravity direction for CharacterController 1 Answer

Gravity and jumping is wierd 1 Answer

When I move my arms back and forth, the player stops falling or moves upward 2 Answers

A node in a childnode? 1 Answer

reading a .csv file on a mac? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges