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 /
avatar image
0
Question by bubblegumsoldier · Oct 15, 2011 at 11:50 AM · jumplerpzdouble

double jump

Hi guys I'm working on a 2d platform game and i've got the code from the unity tutorial "Lerpz". Now I want my character to do a double jump. You press jump once... he jumps normal. When you press it while he's jumping normal again you do a frontflip. Here is the code.. I already tried some things but nothing worked:

Click here to see the code

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by DavidDebnar · Oct 17, 2011 at 09:28 PM

Hi, I redid and tested the code and it works perfectly. Feel free to tweak the values.

 #pragma strict
 
 @script RequireComponent(Rigidbody); //forces this gameObject to also have a rigibody component
 
 //public variables
 
 var maxAirJumpCount : int = 1; // 1 for a double jump
 
 var normalJumpForce : float = 8; //strength of the normal jump's impulse
 var airJumpForce : float = 5; //strength of the double jump's impulse
 
 var raycastDistance : float = 1; //distance between the characters origin and the ground, 1 for a 2m high character
 
 var xSpeed : float = 10; // horizontal speed of the character
 
 /* These values are all ideal settings that worked for me */
 
 //private variables
 
 private var airJumpCount : int = 0; //how many more times can the player jump?
 
 private var xMove : float; // horizontal input (Input.GetAxisRaw("Horizontal")) *
                             // horizontal speed modifier (xSpeed)
 
 private var isGrounded : boolean = false; //is the player on the ground?
 
 function Update() {
 
     if(Physics.Raycast(transform.position, -Vector3.up, raycastDistance)) {
         
         isGrounded = true;
         airJumpCount = maxAirJumpCount;
     }
     else {
         
         isGrounded = false;
     }
 
     if(Input.GetKeyDown(KeyCode.Space)) {
         
         if(isGrounded) {
             JumpNormal();
         }
         else if(airJumpCount > 0) {
             
             airJumpCount -= 1;
             JumpInAir();
         }
     }
 
     xMove = 0;
     xMove = Input.GetAxisRaw("Horizontal") * xSpeed;
 
 }
 
 function FixedUpdate () {
     rigidbody.AddForce(Vector3.right*xMove);
 }
 
 
 function JumpNormal () { rigidbody.AddForce(Vector3.up * normalJumpForce, ForceMode.Impulse); }
 
 function JumpInAir () { rigidbody.AddForce(Vector3.up * airJumpForce, ForceMode.Impulse); }

---David

Comment
Add comment · Show 8 · 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 bubblegumsoldier · Oct 18, 2011 at 11:18 AM 0
Share

thats all or do I have to wirte it in my script?

avatar image DavidDebnar · Oct 18, 2011 at 01:07 PM 0
Share

This is just a pseudo code that shows you how to make it. Just add a JumpNorm() and JumpDouble() functions that will do the jump and double jump and it will work.

avatar image bubblegumsoldier · Oct 18, 2011 at 05:04 PM 0
Share

yes exactly that's the thing what things are in these functions? The code is in the link I#m just too stupid to do this. Usualy I can write every script I want but this time I#m just kind of... stupid. Sorry... please!

avatar image DavidDebnar · Oct 19, 2011 at 05:06 PM 0
Share

Sorry, but I don't have time to read your script, but just do this. If function in which you make the char jump add the things above. Then declare the vars at the start and make another two function JumpNorm() and JumpDouble(). Then add your usuall jump code to JumpNorm() and your double jump code to JumpDouble().

  • $$anonymous$$

avatar image yu-gi-master · Jan 28, 2013 at 01:49 PM 0
Share

private **e**var grounded : boolean = false;

did you men private var grounded : boolean = false;

Show more comments
avatar image
0

Answer by bubblegumsoldier · Oct 19, 2011 at 07:05 PM

OHH It worked if somebody wants the script here's the link

Comment
Add comment · Show 2 · 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 DavidDebnar · Oct 20, 2011 at 05:41 PM 1
Share

Things I would like: Edit your questions and add a link to the solutions in there, and tick the correct answer/close the question.

avatar image bubblegumsoldier · Oct 21, 2011 at 10:38 AM 0
Share

but maybe somebody want to add something later at this question and has a script that's better or so

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

About character doublejumping. 1 Answer

How to jump multiple times to mid air? 3 Answers

Turn off Lerpz Jumping, and turn it back on when he picks up a specific fuel cell? 1 Answer

Double Jump? 2 Answers

Jump is registered when falling of platform? 1 Answer


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