I’m developing a space sandbox building game and I’m running into a serious lag problem
My planet will orbit the star, and it will also spin on its axis
When I land on a star without any buildings, the game runs fine with no lags
But when I started building buildings on the planet, with only a small number of buildings, the whole game started to freeze drastically. As the number of buildings increased, it couldn’t play the game normally.
One of my buildings is an actor. After the building is generated, it will be attached to the planet so that the building and the planet remain relatively stationary.
The main cause of lag is planetary rotation. When I disable all rotations and keep the universe still, lag no longer occurs.
Is there a way to optimize game performance while retaining the planet rotation game mechanism?
I’d guess that the performance impact comes from updating all the transforms/physics. But you should profile to make sure.
If you haven’t already you could try to disable collisions so that these actors don’t have to update their overlaps whenever they change due to the planets rotation.
Also since everything is relative you could instead do it the other way around. Make your planet stationary and then have the camera rotate to fake the planets rotation. You’d also have to change how the star and other planets move around as well though.
In fact, I have been focusing on optimization during the development process and pursuing the minimum consumption
But I completely ignored the collision problem of this building! I didn’t expect the collision issue to cause such severe lag!
Due to severe lag, I have also considered the second solution you proposed, but this will make network synchronization difficult. I hope that my game can be connected by multiple people.
Fittingly, my game doesn’t need these collisions
This is the effect after I turn off collision, the frame rate can reach more than 110 frames