0
\$\begingroup\$

I'm thinking about programming a 2d simulation of a spaceship that takes damage depending on where the projectile came from (e.g. from behind - engine, from the front - lasers, sides - hull, etc.). When a given part is below a certain durability factor it explodes into physics simulated particles. What is a good way of storing such particles (ship built out of parts, parts built out of particles, e.g. 6px triangles) taking into consideration the following:

  • different parts have different shapes,
  • it might be needed to add more parts in the future,
  • possibility of avoiding a pixel-perfect projectile-to-part collision detection,
  • the spaceship should be affected by physics but particles shouldn't unless exploding.
\$\endgroup\$
  • 3
    \$\begingroup\$ I'm voting to close this question as off-topic because one question per question, please. \$\endgroup\$ – Almo May 27 '16 at 22:36
  • \$\begingroup\$ @CyprianGuerra Questions about improving questions are best handled in GDSE Meta - more info about GDSE meta here \$\endgroup\$ – Pikalek May 28 '16 at 4:22
3
\$\begingroup\$

A rational approach might be to simplify your problem. This is a game, so most of the time there is no need for 100% accurate physics.

Instead of tracking every single component that makes your ship, you can instead prepare several damaged ship models and swap then on the fly as it gets more and more damage.

When you swap the models, you could spawn some particles that reflect what probably got damaged at that life level of the ship.

By just loading a model, you save the extra time it would have taken per frame to calculate collisions of each piece of the ship with each other (among other things for all the objects), you also have less code to deal with. This will provide less opportunities for bugs and from a gameplay perspective might give you similar output like what you originally wanted.

Note that if your gameplay totally depends on accurate simulation of destruction, then of course this approach will not work.

\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer, it has been helpful although I already did a project similar to what you described in the past and now am trying to enrich it with simple (not 100% accurate) physics. It's just a learning exercise so I don't mind bugs that much. I did realise, though, that I cannot tackle this all at once and decided to program few particles simulations first. Thanks again. \$\endgroup\$ – cprn May 28 '16 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.