Collision Detection with DrawMeshInstanced
Howdy All,
I am building a space type game, and have developed a script that at runtime, generates 15,000 random locations in world space (which is bound to an area), which then instantiates (you guessed it) 15,000 GameObjects with Mesh Colliders (Convex) and Rigidbody's, which are all pooled.
I'm able to get about 60fps on a GTX 980TI, though not everyone would have that, and I need to target for a lower audience.
I've profiled and can see where savings can be made, from this I introduced a second script which utilizesGraphics.DrawMeshInstanced
to draw the different asteroids.
I need to be able to have the player collide with these asteroids, however simply being mesh's rendered through the pipeline, and no longer GameObjects, this requires some workaround.
I've thought of the following solution;
Pre-pool an array of about 500 gameobjects, of each different type of asteroid with Colliders and the default mesh
All Asteroids will pool into an array of their own type, being rendered via
Graphics.DrawMeshInstanced
Script to detect if the player is close enough that collision would matter, if triggered it would disable that asteroid from the array that is rendering through
Graphics.DrawMeshInstanced
, grab the current transform for that asteroid and apply it to one of the pre-pooled gameobjects to test for collisionApply collision script stuff
When out of range, have the gameobject disable, and re-enable the asteroid in the array for rendering via
Graphics.DrawMeshInstanced
.
I am curious if there is a better solution to this, I've scoured the internet for a couple weeks before making this post, as I know not doing your research first and thinking of solutions is quite frowned upon..