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 SenshiKenpachi · Sep 27, 2018 at 06:41 PM · inputheightpointer

Different Jump Heights: Input.GetKey vs Pointer Down

Hi,

I am creating a very simple platformer and have noticed a very strange behavior when playing it on Android: while testing on PC, my obstacles were very easy to overcome but once on my phone they were almost impossible to beat. For PC controls, I am using LeftArrow, RightArrow and Space. On Android I am using 3 UI elements and Pointer Down events. I did some experiments and added an UI element to display the max height of my character after each jump and this confirmed my expectations: 2.218 on PC and 1.834 on Android (or on PC using the UI to jump) If I set a multiplier of 1.145f on the UI jump, then the jump height is almost the same. Why is the jump height different when it should be the same for both methods??

   if (Input.GetKey(KeyCode.Space))
     {
         if (onGround)
         {
             rb.velocity = new Vector2(rb.velocity.x, jumpheight);
             boink.Play();
         }
     }
 
     if (jump)
     {
         if (onGround)
         {
             rb.velocity = new Vector2(rb.velocity.x, jumpheight * 1.145f);
             boink.Play();
         }
         jump = false;
     }
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
Best Answer

Answer by hexagonius · Sep 27, 2018 at 07:10 PM

use the Input.GetKeyDown method to achieve the same effect.

Comment
Add comment · Show 3 · 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 SenshiKenpachi · Sep 27, 2018 at 07:29 PM 0
Share

thaks a lot bro, that fixed it for me! any idea why it is like this? also: any way to make my Ponter Down the same as Input.Get$$anonymous$$ey?

avatar image LCStark SenshiKenpachi · Sep 29, 2018 at 12:54 PM 0
Share

If you use Get$$anonymous$$eyDown method (or the UI), the code setting the vertical velocity will execute exactly once - for Get$$anonymous$$eyDown it will be during the frame in which Space press was detected, for the UI in will be in the frame in which jump is detected to be true.

If you use Get$$anonymous$$ey, it will be executed during more than one frame - for as long as you press the Space key and your character is still marked as onGround. This means there will be some frames during which your character would be already slowing down due to gravity, but you're resetting its vertical velocity to jumpHeight. Place a Debug.Log("Jump!"); before rb.velocity = new Vector2(rb.velocity.x, jumpheight); and see how many times it's setting the speed per "single" space press. Even if you press and release the space key very quickly, there will be more than one "Jump" in your console.

Also, if your question was answered and you want it to be closed, mark hexagonius' answer as the correct one.

avatar image SenshiKenpachi · Sep 27, 2018 at 07:30 PM 0
Share

hexagonius ·

use the Input.Get$$anonymous$$eyDown method to achieve the same effect.

--> closed

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

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

Windows 8 / Store App: Inputs (WM_POINTER) 0 Answers

IPointerEnterHandler / IPointerExitHandler and touch 1 Answer

IPointerEnterHandler doesn't work when object switches parent 1 Answer

How to reset IsPointerOverGameObject(-1) after click? 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 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