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 HomeSpunGames · Apr 15, 2012 at 11:27 PM · jumptogglevehicle

Keep character from jumping more than once?

Hey Unity community!

I am working on a racing game, and am finalizing the drifting mechanic. I want to make the drifting work like it does in Mario Kart, in which holding the button produces a small hop, then initiates the drifting physics. I have already got the drifting physics working, but I am having an issue with the small hop. Currently, holding down the drift button produces the hop, but the vehicle continually hops until the button is let go. How do I set up my script so that the vehicle will only hop once per hold?

Here is the jump script that needs to be changed:

 var speed : float = 10.0f;
 var jumpForce : float = 1000.0f;
 var airModifier : float = 0.2f;
 var grounded : boolean;
 
 // Update is called once per frame
 function Update () 
 {
     if (Physics.Raycast(transform.position, -transform.up, 2)) 
         {
             grounded = true;
         } 
     else 
         {
             grounded = false;
         }
 //jump if the user pressing button AND our character is grounded
     if (DriftButton.playerJump && grounded)
         {
         rigidbody.AddRelativeForce(transform.up * jumpForce, ForceMode.Impulse);
         }
 }

Any help would be great!

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
1
Best Answer

Answer by Lttldude · Apr 15, 2012 at 11:35 PM

Add a small wait time condition:

 var speed : float = 10.0f;
 var jumpForce : float = 1000.0f;
 var airModifier : float = 0.2f;
 var grounded : boolean;
 var jumpWaitTime : float = 1.0;
 
 private var nextJumpTime : float;
 
 // Update is called once per frame
 function Update () 
 {
     if (Physics.Raycast(transform.position, -transform.up, 2)) 
        {
          grounded = true;
        } 
     else 
        {
          grounded = false;
        }
 //jump if the user pressing button AND our character is grounded
     if (DriftButton.playerJump && grounded && Time.time >= nextJumpTime)
        {
        rigidbody.AddRelativeForce(transform.up * jumpForce, ForceMode.Impulse);
        nextJumpTime = Time.time + jumpWaitTime;
        }
 }
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 HomeSpunGames · Apr 15, 2012 at 11:38 PM 0
Share

Thanks for your reply! This works fairly well, except it just waits for the defined time before jumping again. I really need to get it to jump once, then not jump again until the player releases the button.

avatar image Lttldude · Apr 16, 2012 at 05:31 AM 0
Share

Do you have the ability to recognize when DriftButton.playerjump is down or up? I'm only used to normal keyboard inputs, where they do have a key down/up. If that's the case, just set a boolean variable called canJump that has to be true for the conditional jump statement. Should true on start, false when the playerJump key goes down, and true when the key is let up (allowing for another jump to happen).

avatar image
0

Answer by hernaez · Dec 21, 2012 at 09:44 PM

I'm working on a drift for a mario kart clone, could you help me out with the drift code?

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

6 People are following this question.

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

Related Questions

Game with Multiple Vehcicles - 1 Player 1 Answer

How can I detect the time someone uses input? 1 Answer

What's wrong with this script? 4 Answers

Using a touch event for character motor 0 Answers

First Person Controller (Suddenly Jumping high) 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