0
votes

I made a 2D game with some sprite move to random position. I used Vector2.Lerp and Time.deltaTime to smooth transfer of sprite.
When I build this game in iOS ( I used iPhone 4s and iPhone 5 for test ) all sprite made jerky motion and cause my game lagging. But in Android game run very smoothly.
I used only 9 sprites and move all in same time. Can someone have any solution to fix this? Thanks.
P/s: Sorry about my bad English.

2
this needs more information...are you doing anything in the background? like loading images? or sounds? or playing sounds?Rudolfwm
No. I just move some sprites ( exactly 9 sprites ) at same time in my scene. And don't do anything else.Sting Hà
have you tried looking at the profiler? are you seeing spikes in frame rate? if (as I suspect) garbage collection is your problem try to prevent using temporary lists and such. Reuse memory as much as possible. Also, it may be worth doing a deep profile and optimize your 4 most costly per update function calls.Rudolfwm
I used GameObject Pool to reuse my sprites, but i think Vector2.Lerp cause that jerky motion, i will try to improve this method.Sting Hà
You should be using using vector2.lerp with Time.delraTime. If you are using that, the only thing i can think of is garbage collection spikes happenibg. But without any code there isnt much we can do.Rudolfwm

2 Answers

1
votes

It's a little hard to divine the solution without more info, but some possibilities:

  • Try doing your Lerp in FixedUpdate instead of Update. Unity calls FixedUpdate at regular intervals, while Update is called basically as often as possible, thus FixedUpdate is lighter on your hardware. FixedUpdate is also in-sync with Unity's physics, which will help avoid collision weirdness down the road.
  • Not totally scientific, but elsewhere on StackOverflow I have seen this issue(iOS laggy Lerps specifically) solve by upping the frame rate cap from 30 to 60 fps.

Also, you probably don't want to use Time.DeltaTime for your Lerp. Lerp takes(start position | end position | percentage between said positions), so while transform.position + Time.DeltaTime will result in an 'ease out' effect, it's not one you'll have a lot of control over. I recommend these articles for a better understanding of Lerp, especially the second one because it demonstrates how to use Lerp to obtain all sorts of sexy smoothed movement.

1
votes

Change the value of FPS using the following code

Application.targetFrameRate = 50;