• 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 aleichert · Jul 04, 2017 at 12:22 PM · android2duiphysicsphysics2d

Maintain equal physics over different UI sizes?

Hello, quick question.

I am making a fishing game for Android similar to how fishing works in Stardew Valley. There is an area (UI Image) which you need to keep over a moving fish (up and down). Down is set by rigidbody2d gravity on the UI image, up by add force on the UI image. Gravity is calculated through selected gear, upward force through subtracting the "speed" stat of selected gear from the gravity. Canvas is set to screenspace camera and to scale with screen size.

The problem: Gravity/AddForce act differently based on screen size. Maybe due to the UI getting bigger the bigger the screen is, thus requiring more force to elevate and gravity to drop?

I thought to maybe multiply the UI image rigidbody2d with a number calculated from screen height which gets bigger the higher (read: larger) the screen is to compensate this. How could I do that? Are there other possibilities?

Many thanks! :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by merkaba48 · Jul 04, 2017 at 07:16 PM

No experience using physics on UI elements...but check that the mass isn't automatically generated (it's a flag in the RigidBody2D inspector). If it is, then Unity will increase the mass of the object the larger it is.

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 aleichert · Jul 04, 2017 at 09:11 PM 1
Share

Hi, thanks for your answer. No, the mass isn't automatically generated. I think the reason that it behaves differently on different screen sizes is due to the fact that the UI scales with the screen. The larger the screen, the larger the UI - which means it has to travel greater distances in equal time to behave the same as on a smaller scale.

I'll put some research into it tomorrow and compare the sizes and forces acting onto it in realtime through the Logger. $$anonymous$$aybe I'll find an answer there.

avatar image
0

Answer by LimaoMatador · Jul 04, 2017 at 10:23 PM

I've never tried to add Rigidbodies to UI elements either, but you'll probably have some problems, since rigidbodies use absolute 2D world coordinates and the UI element uses screen space coordinates that are relative to the UI element anchor, so you're probably right about the UI scaling changing your object behaviour.

I advise you to create a 2D GameObject with the Rigidbody2D in your game world, without any sprite or graphics. It's just a reference object that will be driven by your game rules. Then, create a separate UI element that follows that object. To do that, you'll need to convert the object's world position to UI screen space.

If you don't know how to do that, this thread has some solutions: How to convert from world space to canvas space?

I guess this setup is more reliable, hope it helps :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Help with 2D physics script 1 Answer

Scroll Rect Content Disappearing (Video) 1 Answer

How to rotate a GameObject with another GameObject while simulating gravity? 2 Answers

Get information on ignored collision 1 Answer

Limit player speed (2D) 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges