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 /
  • Help Room /
avatar image
0
Question by oussama_bonnor · Mar 16, 2017 at 04:27 PM · c#androidmobilerigidbody2dforces

Why the AddForce fonction works differently on different mobiles ?

I have a basketball throwing game and each mobile i test it on, it acts differently. I am using a fonction that i wrote to make the ball jump by adding a force to it's ridgidbody without using the Time.deltaTime or Time.FixedDeltaTime and i am calling that fonction within the FixedUpdate fonction, yet this problem happens...any ideas ? p.s: i tried it with the impulse force mode and without.

  public void jump(Vector3 Direction)
     {
         //adds force to rigidbody
         GetComponent<Rigidbody2D>().velocity = new Vector2(0, 0);
         GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.None;
         Vector2 direction = new Vector2((Direction.x) / 10, 100).normalized;
 
         //force is a pre-determened variable that i use for diiferent kind of balls
         GetComponent<Rigidbody2D>().AddForce(direction * force, ForceMode2D.Impulse);
 
     }

Comment
Add comment · Show 5
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 ScaniX · Mar 16, 2017 at 04:29 PM 0
Share

Acts differently? Different strength? Fails to do anything sometimes?

Are you calling this function continuously or once? Are you using On$$anonymous$$ey() or On$$anonymous$$eyDown() to trigger it or something else?

avatar image oussama_bonnor ScaniX · Mar 17, 2017 at 01:32 PM 0
Share

Different strength, sometimes acts up to an insane level. Calling it once per click (on mobile). I used a temporary solution which is to calculate the amount of force suitable on that perticular phone starting from a pre-deter$$anonymous$$ed force, and then using the distance the ball went for using the pre-deter$$anonymous$$ed force, to calculate the new more suitable force to apply (calibration).

avatar image NoseKills · Mar 16, 2017 at 04:52 PM 0
Share

On this forum at least, about 90 percent of these kinds of problems are caused by handling the (key)input in a way that causes the AddForce call to happen on a few consecutive Update/FixedUpdate calls depending on framerate or other factors. You should show some code related to how this method is called and explain what exactly "works differently" means.

avatar image oussama_bonnor NoseKills · Mar 17, 2017 at 01:38 PM 0
Share

this is the part where the fonction is called, works differently means the object im adding the force to gets shot further in some devices then others. In other words, the outcome of force added isnt the same although the amount of the force it-self is the same.

if (Input.Get$$anonymous$$ouseButtonDown(0)) { t = Input.mousePosition; } if (Input.Get$$anonymous$$ouseButtonUp(0)) { t2 = Input.mousePosition; if (!waiting && Vector2.Distance(t2, t) > width * 0.5f && !clicked && Vector2.Distance(t, gameObject.transform.position) <= width && t2.y > t.y) { jump(t2 - t); } }

avatar image NoseKills oussama_bonnor · Mar 22, 2017 at 04:24 PM 0
Share

Input.mousePosition returns the touch position in pixels. So 1cm drag on a high resolution (dpi actually) device adds more force than a 1cm drag on a low resolution device.

Depending on what you actually want, you should probably use for example Camera.screentoWorldPoint to convert pixel positions to world coordinates, so dragging the same distance in proportion to your game objects causes a proportionate force or Screen.dpi so that pixelsize doesn't affect the force.

Also if the code you show is located in FixedUpdate, depending on framerate, the force might be added multiple or zero times with one drag.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by AquaBomber · Mar 16, 2017 at 08:37 PM

It probably adds different forces because you are adding force bases on the fps rate.To fix it you have to multiply your force by the deltaTime(frames in one second / 1) so : GetComponent().AddForce(direction force Time.deltaTime, ForceMode2D.Impulse);

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 oussama_bonnor · Mar 17, 2017 at 01:34 PM 0
Share

I already tried your solution and it didn't really help, i even tried to set the fps to 30, or using the VSyncCount and setting it to 2 to slow down the rate. NO change.

avatar image pirisok oussama_bonnor · Oct 08, 2019 at 12:58 PM 0
Share

hi, did you manage to fix this? how?

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

12 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

Related Questions

Is Collider 2D and OnMouseDown a good combination for mobile? 0 Answers

How to replace space keyboard with a simple tap on Android? 0 Answers

Is it possible to access the native step-counter on mobile platforms. 2 Answers

Is It Bad to be Tired of my Own Mobile Game? 1 Answer

Buttons for Player movement 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