- Home /
how should I approach drawing thousands of projectiles in a bullet hell?
I've found it difficult to find help in this regard as I know nothing of how to handle unity's drawing in script.
I know my way around graphics programming for the most part, if the option is available I'd draw the projectiles via hardware instancing (with a custom instance layout so I can define a per instance colour and UV offset) and I would like to draw them using a shader of my writing.
I'd prefer an article or deep tutorial as I'd rather learn than copy.
Answer by TonyLi · Apr 18, 2013 at 02:33 PM
If you're targeting DirectX 11, you could look into TC Particles (http://u3d.as/content/arthur-brussee/tc-particles/4gn) or develop something similar. Someone developed a similar DX11 system that's free, too: http://forum.unity3d.com/threads/172553-DX11-Particle-System-Free. There's also Unity's Shuriken particle system. They wouldn't give you per-projectile collision, but it could work depending on your needs. You could just do a single SphereCast() that encompasses the particle effect to see if it hits anything.
If you're targeting lower end platforms, what about using a single texture/mesh? Again, you wouldn't get per-projectile collision detection, but it really depends on your needs.
I've got collision detection covered, I've written physics engines in the past and this doesn't exactly require complex hit boxes, I'll be handling collision via a spatial hashmap with the projectiles in, each object capable of being hit by the projectiles will get their relative areas projectiles from the spatial hashmap and test against them, I'm doing it this way in particular as I imagine there will be less entities than projectiles. Also I'm targeting lower end platforms, my PC itself is a bit dated only boasting a GTX 260 so I cant run most of DX11. what do you mean by using a single texture/mesh? do you mean batching? if so is this possible in unity free and how would I do this?
Using a single texture is an ultra low-tech, inexpensive approach that may or may not satisfy your needs. In a 2D game, you just draw a texture with transparency that contains a ton of bullets, or a texture atlas with multiple frames that you can animate. Then apply this to a plane that moves in the direction of the shot. In 3D, you could put it on one or more spheres. You could even apply some animated scaling or rotation for effect.
I guess you could say it takes advantage of Unity Free's dynamic batching, since it's only using a single texture/material. But it's even more rudimentary than that, and may not be sophisticated enough for what you need. Then again, the best solution is the simplest one that gives you the effect you want, right?
well I was intending to use a texture atlas anyway, my concern is handling the geometry, I don't want a gameobject for each projectile for obvious reasons (its a complete waste of resources) I'm just not sure how to draw efficiently in script, I made the assumption that batching didn't work in script, if batching does work in script them by all means thats a solution found.
Batching works by geometry (and material), whether it's script-controlled or not. $$anonymous$$y single-plane or single-sphere suggestion uses only one mesh with one material, but then again it has its limits.
if by 1 mesh you mean 1 big mesh then I don't know how I would move the projectiles around, but I'm assu$$anonymous$$g by 1 mesh you mean multiple instances of 1 mesh, which I'm most likely to do, the camera being orthographic I can just use images and billboard planes.
Your answer
Follow this Question
Related Questions
The combined mesh is different between static-batched objects? 0 Answers
Why aren't my particle systems batched? 1 Answer
Batching runtime instanced Objects 0 Answers
Dynamic batching stops when I disable "cast shadow" 0 Answers
Do statically batched meshes need to have the same pivot point(not position)? 0 Answers