Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 MikeMcDonald · Jul 29, 2015 at 05:39 PM · mobilevelocityphysics2dscalingmobile devices

Constant speed across mobile devices using 2D physics velocity?

We're working on a simple physics game that involves bouncing a ball off of a paddle. We set the velocity of the ball so that it stays constant (_ball.velocity = 500 * (_ball.velocity.normalized)). Problem is that when we deploy the build onto various mobile devices the ball moves at different speeds across the different devices. This is all done in 2D. The objects use rect transforms and rigidbody2D components. We have tried various methods of compensating for different screen sizes and densities, but none have worked. For example, we tried multiplying our velocity by (Screen.width / GetComponent().referenceResolution.x) which has solved other screen size issues for us, but did not work for creating a consistent speed across devices. Any help?

UPDATE: We figured out that the appearance of different speeds was caused by the lower-end devices lagging. The lag on those devices ends up causing everything to move slower than expected. I would have expected the physics engine to compensate and cause some frame loss, not reduce speed. The problem was further obscured by our attempts to compensate for delta-time and dimension which appears to be unneeded.

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 MikeMcDonald · Jul 29, 2015 at 04:01 PM 0
Share

In short it's: _ball.velocity = 500 * (_ball.velocity.normalized)

We just set the velocity of the ball. We've tried adding things to that calculation like deltatime and the screen width / reference resolution as listed above, but nothing has made it move at a consistent rate across devices.

However, after that it's Unity's physics engine that is ultimately controlling the movement of the ball. Some devices it will move crippling slow on and others it will move blazingly fast.

avatar image Owen-Reynolds · Jul 29, 2015 at 06:28 PM 0
Share

That math (velocity to 500) looks fine to me. Velocity is in meters/second, and the physics system automatically tries to compensate for frame rate to do that.

But, the objects use RectTransforms? So movement becomes more-or-less in pixels (the game pretends every pixel is one meter)? In that case, clearly something like your screen.width/reference.width is needed, since the "world" grows and shrinks with the device. Are the devices the same aspect ratio (so you don't also have to worry about the height)?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kh4yer · Sep 17, 2017 at 05:18 PM

Help @MikeMcDonald When I move my ball using

 Ball.transform.position += Ball.transform.up * speed *Time.deltaTime;
 //or
 Ball.transform.position += Ball.transform.up * speed ;
 

It moves at different speeds depending on the resolution

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is there any difference between mobile and desktop physics? 1 Answer

Rigidbody 2D loosing velocity 0 Answers

how to make an 2d object move the direction its facing using rigidbody2d.velcoity 1 Answer

using GooglePlayGames; not working? 0 Answers

how to jump at fixed height but faster 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