Malen Kihren2019-10-26 13:24:05
Game development
Malen Kihren, 2019-10-26 13:24:05

25,600 moving sprites?

Good afternoon.
Problem statement:
We need to create a grid of 160x160 sprites. Each sprite moves in a random direction and at a random speed. When colliding with each other, the sprite disappears and reappears a second later, somewhere behind the screen. It is necessary that it all work at 30-60 fps.
My decision:
In the Spawner script I have 3 sheets with speed, direction and rigidbody2d. At the start, I create sprites, put them on the grid in a double loop, immediately randomize the speed and direction, and add them to the lists together with rigidbody2d. In the FixedUpdate method, I loop through all the items in the rigidbody2d list and give each one its direction and speed. A script hangs on the sprite, which monitors the collision through OnTriggerEnter2D and calls a method from Spawner in which this sprite turns off, moves off the screen and is activated there again and continues to move. I was able to get 20 fps at 120x120 sprites.
Question: What optimization methods can still be applied?
Ps: I read about ECS & Job System if they will help me in this case, because I use movement through ridgedbody, not transform. If so, could you show with a simple example how it should look like.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Griboks, 2019-10-26

Yes, they will help. Don't forget to use a profiler as well. Also use a transform, and check the collisions yourself. Also, use life hacks like check x2-x1 instead of crossing boundaries, use distance squared, etc.
In addition to the physics itself, I advise you to optimize graphics, in particular sprites.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question