I’m working on an easy shoot 'em up game for mobiles. According to the limitations to two thumps controlling i need a vertically aiming help. Like in Doom1&2 for example.
My idea right now is to use a collider that scans by tag for enemies and set the next to the player (if any) as the target. I’m using raycasts to shoot…
I’m wondering if this would be to expensive for an android game and if there is a better way. Like shooting more rays up and down and take the one that hits something - with fallback if no enemy was hit.
That’s not an easy task with such limitations. Your idea is good, and I think it can be less expensive if you place all enemies in some user layer, than use Physics.CapsuleCast in this particular layer to find only enemies: CapsuleCast projects an imaginary capsule in the direction and distance specified, and returns the first collider hit, thus all you have to do is shoot the collider returned, if any.
Ideally, the volume cast should be pyramidal; to get something slightly more similar to this you could do a short CapsuleCast with a smaller capsule, and if nothing found do another CapsuleCast, this time with a larger capsule and starting where the smaller one finished.
Instead of casting, i think your approach could be modified (and should be inexpensive depending on the enemy-count/-density):
Keeping a list of enemies inside the collider attached to the player and then filter that one (e.g.: for those being within a certain horizontal angle from the reticule, shoot the center- & front-most of those).
With few enemies that should be rather inexpensive, but then again i haven’t done measurements on those… Building a few test-cases (casts vs. book-keeping/filtering) and measuring how much time they take over a few hundred iterations should be relatively easy though.