- Home /
Simple 2D motion around a circle is laggy in Android.
This is my first time on Unity so sorry for all the noobness.
I am making a simple 2D game in which an object (call it M) keeps running around a circle, with simple obstacles(call it B) in its path. Thats pretty much it.
I do not use any gravity.
Have added a Rigid body on M. And have added box2d colliders both on M and B. Both the colliders are triggers.
I have made M go around the circle using the RotateAround method of unity.
The issue is that, the motion of M around the circle is very laggy in android. And this is not a phone issue, as this lags even on good phones like the nexus 5.
I have read quite a few of the threads on lags on android, have tried to implement those fixes. Still not much improvement.
There are just 4 images in total, and all of them are part of one png file, and have used the unity slicer to create separate sprites. Any inputs? I wouldn't mind sharing code as well.
Could we get the code you used to do this? If we can see what you've done, we can probably help a lot better. Are you doing this rotation in a FixedUpdate or an Update? Or are you using some other sort of inter-frame iterated method calling, such as a coroutine?
You can check out the code over here. https://bitbucket.org/neilunadkat/unity-save-your-bananas. Have made the repo public for now. I tried the rotation in both Update and FixedUpdate. Not much of a change.
This is my first time in Unity, so my code might not be elegant .
So I had started learning about Unity with the same project as above.. So there could be random scripts which would be executing update calls..
Today I sat and made the whole thing from scratch. Completely new project. And This time i knew what needed to be done, so nothing extra. There is hardly any lag..
Answer by NickP_2 · May 31, 2014 at 02:51 PM
Make sure that anything which affects a rigidbody (such as rigidbody.AddForce(...)) is in the FixedUpdate() function. This function is called right after, or during (not sure) the physics update!
I am not using any force or gravity. The only physics part I am actually using is the collision detection using the box collider and rigid body. You can check out the code at https://bitbucket.org/neilunadkat/unity-save-your-bananas