Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 unity_zKPx51wsX8Zd8Q · Jan 09, 2018 at 03:23 AM · programming

so im making a game and i wondering how would i put a delay between jumps

// Update is called once per frame void FixedUpdate () { rb.AddForce(0, 0, forwardForce * Time.deltaTime);

     if (Input.GetKey ("d")) 
     {
         rb.AddForce(forwardD * Time.deltaTime, 0,  0 );
     }
     if (Input.GetKey ("a")) 
     {
         rb.AddForce(forwardA * Time.deltaTime, 0,  0 );

     }

     if (Input.GetKey ("w")) 
     {
         rb.AddForce(0, forwardw * Time.deltaTime,  0 );
     }
 
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Honorsoft · Jan 09, 2018 at 04:27 AM

You could use Unity's built-in "yield return new WaitForSeconds(SECONDS);" function, but it has to used in an IEnumerator function (Coroutine). The example for Coroutines/IEnumerators is at: UnityDocs:WaitForSeconds However, for jumping, a better method is to set up a Boolean (true/false) to see if the player is allowed to jump yet or if it is already jumping. Or, keep track of whether the player "canJump" or not. I am guessing you want to delay the time between jumps because you don't want to try to jump while you are already jumping. So you could declare bool canJump = true; at the start of your script with the other variables, and then change the if (Input.GetKey ("w")) into if (Input.GetKey ("w") && canJump = true) You want to know when you are able to jump at all times so when you do JUMP, in the start of the JUMP function, set the bool canJump to false. When finished jumping, set it to true so you can jump again.

If you want to know when the player has finished jumping, there are many methods like timers or player-position checking, but a good way is to determine when you've landed. That can be done with collision checking in Unity. It's not hard, use the void OnCollisionEnter(Collision collision) and void OnCollisionExit(Collision collision) functions to know when a collision has taken place and when one has stopped(Exit). There is someone else working on a similar jumping script: Jumping In Mid Air

PS, The way your script is now, the jump button (w) will function like a rocket, it is called every frame from Update() so every frame it's pressed will add upwards force.

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 Honorsoft · Jan 10, 2018 at 05:17 AM 0
Share

Oh yeah, the AddForce function has a Force$$anonymous$$ode, you can use the Impulse (see Unity's script documentation) mode to send a quick burst of force that will have more of a jump effect. I've noticed though that using AddForce physics to make an object 'jump' will also cause random turning and twisting even on a flat 3D surface, so a controlled scripted 'jump', or an animated 'jump' in Unity might be more suitable.

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

79 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 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 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

Multiple Cars not working 1 Answer

Prior Knowledge 0 Answers

Make a game in C# 0 Answers

How to start in Unity? 1 Answer

Mecanim Jump up HELP!! 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