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 TRON-dll · Jun 11, 2013 at 07:57 PM · 3dplatformerthird-personfirst person controllerdouble jump

Is there any way to do a double jump with the first person controller?

Hey, I'm working on a platformer game and I'm re-working the first person controller for the player character. Everything has been fine so far, but I need to make the character be able to jump in midair. I think the changes I need to make are somewhere in the character motor script, but I'm not 100% certain. Any help is very much appreciated.

I also found a Unity Package that some guy made back in 2010 that was a modified version of the first person controller to make it function more like the Unreal Tournament 3 player character, which would allow for double jumping. Unfortunately, all of the scripts were missing when I imported it, so I'm not sure if I'm doing something wrong, or if the package is corrupted. If anyone knows a solution to that, I'd also appreciate it.

Comment
Add comment · Show 4
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 superluigi · Jun 11, 2013 at 09:07 PM 0
Share

Please post your script or we cant really help you much.

avatar image robertbu · Jun 11, 2013 at 09:25 PM 0
Share

@superluigi - I believe he is using the standard first person controller script.

avatar image superluigi · Jun 11, 2013 at 09:30 PM 0
Share

There is unfortunately I just updated unity and npw monodevelop isn't working lol when I get it working I'll try to help u out. $$anonymous$$eep in $$anonymous$$d I'm very new to this so I might not be able to help much but I do have a successful double jump script on my character controller albeit its a 2d game.

avatar image TRON-dll · Jun 13, 2013 at 07:17 AM 0
Share

Yeah, I'm using the standard first person controller prefab from the character controller package. I'm just having trouble finding which script handles jumping and where to modify code.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Lockstep · Jun 11, 2013 at 11:44 PM

You just have to remember if the character has already jumped midair:

 public int airJumps = 1;
 private int jumpCounter = 0;
 //you could use a simple boolean instead, but
 //like this you can do a triple, quadruple, etc jump
 
 private bool isGrounded; 
 //The character controller script probably has this already
 //Is true iff the character touches the ground
 
 //inside Update:
 if(isGrounded){
     jumpCounter = 0;
 }
 if( Input.GetButton ("Jump") ){   //Lokate this in the script. It's probably already there in some form.
     if(isGrounded){
         Jump();
     } else {
         if(jumpCounter  < airJumps){
             jumpCounter++;
             Jump();
         }
     }
 
 }
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 TRON-dll · Jun 13, 2013 at 07:16 AM 0
Share

Yeah, that seems like it should definitely work, though I'm a bit confused as to where I should apply this. Would it be in the Character $$anonymous$$otor script or the FPS Input Controller script?

Or would I want to do a completely separate script? I'm just a bit confused.

avatar image Lockstep · Jun 13, 2013 at 10:02 PM 0
Share

The motor script! If i recall it right, then the input controller only manages the input put none of the movement. The reason for this is, that the motot script is also meant to be useable for AI.

I know, that the motor script is a real beast. But consider, that it is able to manage moving platforms, slopes, eliptic speed calculation, smooth acceleration and more in addition to the usuall moving and jumping.

Your goal is to find the place where the Jump() function gets executed: The easiest way to do this is using the search functionallity of your editor. I assume you use monodevelop since it comes with unity. Press control+F or select the icon in the toolbar, then type Jump in the search field. You can also select the function and use - find references - press shift + F12 or select it from the dropdown menu from the right mouse button.

The jump function needs to be executed somewhere in Update ( or FixedUpdate). $$anonymous$$aybe it hides in another function inside of Update. $$anonymous$$eep looking until you found it.

You will probably find it in such a context:

 if(/*some statement that handles Input for jumping*/){    // in my example from above, this is Input.GetButton ("Jump"). It will probably look different.
     Jump();
 }

Then you need to replace the simple Jump() with the block from my example, where we check for grounded or the jump counter.

You also need to make sure, that the original script does not prevent jumping when isGrounded is false. Search for isGrounded in the script and see where it restricts jumping. The only check (for jumping) must be the one from my example above.

avatar image
0

Answer by superluigi · Jun 13, 2013 at 07:44 AM

sorry I'm writing this from my wiiU so I can't look at the controller script right now. Try this:

 var jump : float = 9.0;
 var dJump : float = 5.0;
 var gravity : float = 20.0;
 private var canDJump : boolean = false;
 private var velocity : Vector3 = Vector3.zero;
 var controller : CharacterController;
  
 function Update() 
 {
     if (!controller.isGrounded && canDJump && Input.GetButtonDown ("Jump"))
     {
         velocity.y = dJump;
         canDJump = false;
     }
  
     if (controller.isGrounded)
     {
         if (Input.GetButtonDown ("Jump"))
         {
             velocity.y = jump;
             canDJump = true;
         }
     }
     velocity.y -= gravity * Time.deltaTime;
     controller.Move (velocity * Time.deltaTime);
 }
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 superluigi · Jun 13, 2013 at 08:11 AM 0
Share

make sure the second jump(doubleJump) is on top of the firts jump in the code otherwise it will read both jumps in the same frame so you will jump twice real fast. By putting the double jump on top of the first jump you ensure that it will get read on the next frame so u can jump while in the air.

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

16 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

Related Questions

how to stop double jumping in 2d platform effector 0 Answers

Moving 3rd person player relative to orbiting camera 1 Answer

Troubles making custom 3D character controller (for platformer) 0 Answers

Objects won't disappear after a set time after collision 1 Answer

Need Some Help With Controlls. 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