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 jamsoda · Jul 31, 2014 at 03:48 AM · c#2dphysicsjump

How do i incorporate a double jump ingame?

I have a functioning 2D "sphere" ingame object and i have it resting on a cube object. I can successfully move it left and right, and jump an infinite amount of times in the directions i press. Im having an issue trying to figure out how to put a limit on the jump amount though. I want the sphere to only be able to double jump before it reaches some sort of cap and reached the ground, instead of being able to basically fly with how many jumps it has. Heres my snippet of code so far:

 void Update () 
         {
         //the rotation gets the value of the input (on the horizontal axis) times the
         //value of the rotation speed
         float rotation = Input.GetAxis ("Horizontal") * rotationSpeed;
         //this rotation happens independantly as the frames refresh
         rotation *= Time.deltaTime;
         //sets a torque like movement to the rigidbody2d of the sphere, by minus 1
         //for opposite torqing direction, making right right and left left
         rigidbody2D.AddTorque (-1 * rotation);
 
         if (Input.GetKeyDown (KeyCode.UpArrow) && isFalling == false) 
         {
 
             rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x, rotation);            
             rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.y, jumpHeight);
             isFalling = true;
         } 
         else 
         {
             isFalling = false;
         }
     }
 
     void OnCollisionStay ()
     {
         isFalling = false;
     }

Im still beginning, and im a bit all over the place since i tried multiple solutions but didnt delete any of them. Thanks in advance.

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 Kiwasi · Jul 31, 2014 at 04:32 AM 0
Share

You need to implement a check to see if you character is on the ground. Raycasting is a popular way to do this. Others prefer triggers.

Velocity is dangerous as a projectile under gravity will have zero velocity at the top of its arc. About as far away from the ground as you can get.

avatar image jamsoda · Jul 31, 2014 at 07:46 PM 0
Share

Gotcha, so if i simply look up some Raycasting and/or Trigger solutions I should be on the right track. Gonna have to keep these things in $$anonymous$$d then.

1 Reply

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

Answer by jusabian · Jul 31, 2014 at 08:11 AM

Hi,

I did also a doublejump check with the raycasting method. Simply check with a raycast if the ground is near and let the player jump if the ground is in range. The raycasting could be in a coroutine which triggers a bool variable to allow the jumping, or simply check before the jumping when the player presses the jump button.

Hope it helps,

Jusabian

www.kawetofe.com

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 jamsoda · Jul 31, 2014 at 08:22 PM 0
Share

Hey, thanks for the added advice, will certainly look into those techniques. Gonna test them out tomorrow and hopefully come up with a new batch of code to smooth out the issue. If the thread is still open by that time, i'll paste a code sample.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

C# Water Rotation 0 Answers

Problem with joints 2 Answers

Sucking a zero-gravity ship into a black hole. 1 Answer

Script calling onCollisionEnter2D and onTriggerEnter2D while disabled 1 Answer

2d game platform physics 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