I am trying to make a physics 2D game. Various shapes fall down into an area that bounded by screen size. I added the ground and added walls on the top and sides as well.
When I run it in the Unity Editor, everything works perfectly. However, when I run it on a device like iPhone, some weird things happen. The shapes will start shaking, sometimes overlapped. I’ve tried every solution I can find, but none of them worked.
It has bugged me for 3 weeks. I’ve attached a video showing this issue.
Has anyone experienced this before? Please help me.
Not enough detail to help you beyond guess after guess.
In the very least, please explain/show what each of these circles are comprised of. When is the simulation running? FixedUpdate? Update? What global physics settings have you changed? Are you using the default iterations or have you tuned them?
Guess#1: If each has a Rigidbody2D, is it using Discrete or Continuous collision detection? Discrete will causes overlaps, especially evident in such confined set-ups.
All looks okay in the screenshots albeit you’re not using interpolation which will give you smoother visuals but that doesn’t affect the simulation itself.
You are using the default iterations for the solver. I presume you’re using the default fixed-update rate of 50Hz and not changing this on the device for instance? Also, I presume you’re not using large mass differences for these bodies; I see mass as 0.1. Are they all that? The only thing to be careful with mass is that you try to not go beyond a 10:1 mass ratio in situations like this with things tighly packed and interacting.
I presume there are no other scripts on each of these “balls” that cause movement of any kind? Arer you using multithreading perhaps? If so, turn that off and see if it affects it.
I still cannot tell you what is going wrong though. Certainly start with the basics such as attaching a profiler and seeing if you’re getting poor update rates.
You reminded me that there is actually a script to change the scale of the ball. Now I added a child body with a sprite renderer. The scaling animation script will use this child instead of scaling the parent with rigidbody2d and collider2d. The mass of the ball is between 0.1 and 0.3.
I have checked the Fixed Timestep(0.02) and multithreading (off) .
If you don’t mind, I’d like to add a video showing you another strange phenomenon.
At the bottom of the screen there is a ground object which only has collider2d and SpriteRenderer. during the game, for some reason, the collider path on the ground seems to move down overall.
I tested it on iPhone 13 Pro, iPhone 6 and Google pixel 2 XL. It seems that this problem ONLY occurs on iOS.
BTW, I adjusted the timescale only for showing you the details.