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 Musty · Apr 11, 2015 at 04:58 PM · 2dupdatejumpfixedupdate2dplatformer

2D physics jump issue.

Hey Guys, Im having trouble with this 2D jump. When I jump next a platform it sometimes shoots up really high. From digging around I found that physics should be in fixedupdate but i cant put input in fixedupdate since some input gets lost so im kind of stuck as to how to fix this.

 if((grounded /*|| !doubleJump*/) && Input.GetKeyDown(KeyCode.Space))
         {
             anim.SetBool ("Ground", false);
             r.AddForce(new Vector2 (0, jumpForce));
 
             grounded = false;
 }
Comment
Add comment · Show 3
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 Calum1015 · Apr 11, 2015 at 05:35 PM 0
Share

Have you tried putting it in Update? You might find it still works. You could create an object at the top of the scene to "stop" the player from jumping too high however I see that still wouldn't help. Try putting it in update then reply what it does and I will try to help as best I can :)

avatar image KalleH · Apr 11, 2015 at 06:24 PM 0
Share

You can (and should) check user input in Update ins$$anonymous$$d of fixed update since you only apply the force once while jumping. If you did something constantly (apply force every frame, raycast etc.) then use fixed update.

avatar image _Gkxd · Apr 11, 2015 at 07:48 PM 0
Share

You can also try setting the velocity directly (pseudocode): r.velocity += Vector2.up * jumpAmount.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by DoTA_KAMIKADzE · Apr 11, 2015 at 06:45 PM

You're completely fine using it in Update, but your code that you have shown failed to represent complete issue, so for now I can just point you in the right direction.

If your jumpForce variable is constant value (if not then well that's why...) then the only possible problem from your code is the problem with grounded variable, more specifically - you set it somewhere to true before the player actually hits the ground and you just constantly keep adding force (pushing up) your player. For more detailed guidance we would need the code that sets your grounded variable to true as well as the order it is called and the place (e.g. if both in Update or...?)

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 Musty · Apr 12, 2015 at 06:10 AM 0
Share

Thanks for the replies, so ive tried moving the script from update to fixedupdate and it causes it to not register button presses and the problem with keeping it in update is the fact that it jumps too high sometimes.At the moment im not home so I cant post the rest of the script but ill post it when i get home.

avatar image DoTA_KAMIKADzE · Apr 12, 2015 at 06:59 AM 0
Share

Well I thought I clearly stated that for your case you should leave the code in Update function. FixedUpdate is used for more constant things like for example running. Why? because by default FixedUpdate is "run" "constant" 50 times/sec (it's not a constant time but for its purposes that doesn't really matter and you should use fixedDeltaTime inside it for ti$$anonymous$$gs, also the number is configurable if needed) while your Update is run as many times as your user machine can handle (if without VSync).

For a better understanding what happens you can change your Get$$anonymous$$eyDown to Get$$anonymous$$ey and your char should jump like a rocket to the stars while you hold Space key ))

Now when he will - re-read again my answer what causes your "jumps too high".

avatar image Musty · Apr 12, 2015 at 10:31 AM 0
Share

Yeah I get what you mean now. void FixedUpdate () { grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, Ground$$anonymous$$ask);

This is wher im setting it, but when I debugged it I could see that the grounded variable is not setting to true of false properly. Sometimes its mid air and its set to true.

avatar image DoTA_KAMIKADzE · Apr 12, 2015 at 11:01 AM 0
Share

Then you have exactly the same issue that I have answered 2 days ago.

If that answer doesn't suit you then you should consider changing the way you detect ground. There are many more ways like Raycasting, Linecasting, OverlapArea, etc. Though all of them will need either precise configuration or some sort of a cooldown.

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

22 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

Related Questions

Problem with animation and void fixedupdate() 1 Answer

counter doesnt work in update 2 Answers

2D Animated tile synchronization 0 Answers

Accelerating speed 2 Answers

2D box collider (character floating) 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