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 smirlianos · Nov 02, 2012 at 07:29 PM · javascriptcontrollerjumpjavadeltatime

script for Jump help

I have the follwing part of a character controller code. The problem is that I have to press the jump button the hole time to perform a full jump. How i can make it, so when i press Space one time,it makes the whole jump?

 if(Input.GetKey(KeyCode.Space))
 {
     transform.position += transform.up * +jumpspeed * Time.deltaTime;
     Cam.transform.position += transform.up * +jumpspeed * Time.deltaTime;
         
 }
Comment
Add comment · Show 2
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 smirlianos · Nov 02, 2012 at 07:38 PM 0
Share

Any help??

avatar image phodges · Nov 11, 2012 at 09:22 AM 0
Share

Yes. You seemed to have stopped responding though.

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Nercoe · Nov 03, 2012 at 10:45 AM

You can do this:

 var jumpDelay : boolean;
 var doubleJump : int = 0;
     function Update()
        {
             if( Input.GetKeyDown(KeyCode.Space) && jumpDelay == false)
        {
               Jump();                    
     }
 }
 
     function Jump()
        {
                if (doubleJump <= 1)
        {
             rigidbody.velocity.y = 175;
                 jumpTimer();
     }
 }
 
     function jumpTimer()
        {
          if (Input.GetKeyDown(KeyCode.Space))
        {
                  doubleJump ++;
          }
          
                  if (doubleJump > 1)
                      {
                          doubleJump = 0;
                              jumpDelay = true;
                                yield WaitForSeconds(3);
                                  jumpDelay = false;
             }
         }

Make sure you have a rigid body attached to your character when you do this. I will write you a jump timer now so that the player cannot jump repeatedly, unless that's what you want?

Comment
Add comment · Show 4 · 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 smirlianos · Nov 12, 2012 at 01:46 PM 0
Share

ok, it works, but yes, how can I make a double jump?

avatar image Nercoe · Nov 12, 2012 at 02:00 PM 1
Share

I updated the code for double jump.

avatar image smirlianos · Nov 12, 2012 at 02:27 PM 0
Share

Thanks! :)

avatar image alikkagalar · Aug 02, 2013 at 11:23 PM 0
Share

thanks it works very well

avatar image
0

Answer by MountDoomTeam · Nov 02, 2012 at 08:04 PM

take this command from the unity reference http://docs.unity3d.com/Documentation/ScriptReference/Time-time.html

with time.time, it makes the action repeat only if time + time duration has elapsed and button still pressed.

change the above code abit so that it jumps between the time you press jump and a time elapsed period after.

... make to variables, one = time when button was pressed and two = time when it was pressed + 2 seconds...

and say... if time.time is between time one and time two, 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 MountDoomTeam · Nov 02, 2012 at 08:13 PM 0
Share

sorry i got the above answer wrong first time, it's correct now. although if you manage just with that info it means you already understand how to string 4 lines of code together :)

avatar image smirlianos · Nov 03, 2012 at 09:39 AM 0
Share

I didn't get it...!!

avatar image
0

Answer by theclassicgamer132 · Mar 09, 2014 at 09:55 AM

i should make it: if(Input.GetKeyDown(KeyCode.Space))

instead of if(Input.GetKey(KeyCode.SPace))

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

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

14 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

Related Questions

Unexpected token? 1 Answer

Jump on button press. [JavaScript] 1 Answer

Simple wall jump 0 Answers

Setting Scroll View Width GUILayout 1 Answer

First time open error android game 0 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