▲ 145 r/Unity3D
Im working on a total war type RTS game where each "Unit" is one formation of ~40 men. Each man must regularly:
- measure the distance to each other man around him (for spacing / swarm mechanics).
- check terrain height at his position.
- be rendered and animated.
My attempts so far:
- Grid cell system, so that only men in nearby cells distance is measured, instead of all.
- Reduce distance and terrain height checks to happen only 3x per second.
- Draw men as billboards when not close to the camera and stop animating.
- Changed man from being a monobehavior to being pure data in the Unit script. So each unit instead of a Man:Monobehavior collection, now has pos[40], vel[40], lastAttackT[40] etc arrays for all its men.
- Baked the animation into static meshes like a flipbook, so that Unit:Monobehavior can draw them with DrawMesh(). Each mans animation state and current frame is tracked separately, then:
- for(i=0; i<allMen; i++)
- DrawMesh(flipbook[mesh], Matrix4x4.TRS(pos[i], rot[i], scale), material, mpb);
- and most recently: Tried to group unit TRS matrices in a dictionary by animation and frame, so that all men of the same frame of the same animation can be drawn with DrawMeshInstanced() in one draw call. It didnt work properly and seemed to lower framerate even more.
After all this the framerate is still <20 with only 5 units. The goal is to have 30+ units (~1200 men). I dont know what else to change, and feel like im doing something majorly wrong. How can games like total war have thousands of soldiers on a battlefield, presumably all checking distances to each other, checking ground height, and hundreds if not thousands of draw calls each frame at 60fps ?
u/Accomplished-Oil6369 — 19 days ago