   Should I use physics engine or just write my own?
  Hi all,I've developed a few games without involving complicated physics. However, I would like to add just a little bit physics on my next project: a Tower Defense game.I've searched a bit on the forum but most topics people discussed here are pretty specific. My question is simple.In my next game, I would like to calculate the projection of a canon let's say. I know this is an easy calculation, but would it be better to start using and playing with a physic engine than writing a few formula that only work for this game?I know this question might sound silly, but I would like to know how people think on this question.Thanks in advance.Eagle.   
  That's like asking, should I use a graphics engine or just write my own. The purpose of using code is to alleviate the burden of having certain tasks, the question you should really be asking yourself is would my project be benefited by writing my own library? or what do I hope to gain from it?   ;  Based on my own experiences of both approaches:Pros of (mature) physics engine:Code better tested already than I can test myselfProvides more complex physics than I could write myselfFaster development time and concentration on other game elementsNegs:Certain things become harder/impossible (e.g. horizontal moving platforms with Box2D)Any discovered bugs hard to solve by selfHarder to integrate with objects that are not governed by the physics enginePros and negs of own code basically opposites of above.The precursor to ">my game was a simpler version with self-rolled physics. For as long as I only wanted swinging on a static arm, it was far easier to work with my own engine and integrate things like AI for non-player entities.Then I decided I wanted stable-stackable objects and more complex joints. These are highly non-trivial things so at this point the benefit of using Box2D began to outweigh the above, although certain sacrifices had to be made.In a nutshell, it entirely depends on your priorities for your project and how complex you need physics to be. A full blown physics engine can certainly cause more problems than it solves if applied to a simpler model as it is simply not designed for that. Box2D would be an awkward choice for writing Super Mario for example.   ;  I've spent a good few years messing around with my own engine (mainly graphics/physics), I've learned an incredible amount from doing so. I pretty much replaced the entirity of it in less than a few weeks on and off with Ogre3d + PhysX. My game is now way more powerful, flexible, reliable etc etc in a mere fraction of the time :P.If your goal is learning then I suggest making your own engine. Any other reason then just use a pre existing engine. I would make my own engine significantly differently had I seen how some other engines do things before hand too.   ;  If you only want to perform one or two physical simulations/calculations and you're more interested in the learning/building aspect than producing a working game as quickly and efficiently as possible, then write your own. If you want to get to making a finished game, or if you're not particularly interested in the physics aspect itself, or if you're not that good at physics, or pretty much any other reason, use an engine/library.There are more than enough interesting challenges in the development of even the simplest game that using libraries, engines and so forth is generally a Good Thing™. Happy hacking! [smile]   ;  Keep it simple. Here that probably means that you should just write this yourself. A tower defense game probably only needs a very small number of functions usually covered by a physics engine:-2D box, line, point, and circle intersections-Basic projectile motionFor all of those, I think that the overhead (from a programming perspective) of installing, learning, and coding of using an existing library is much larger than writing and testing your own. I imagine that this could be written in a small handful of functions.One thing that you might consider using is a vector math library. This, too, is pretty easy to write, but since this is helpful in many games it could be worth the time to learn. And if you don't already know the vector math, learning it is a good thing for these kinds of projects and will help in writing the above functions you need.   ;  Thanks a lot guys, each one of your's opinion is very useful to me. I think I will just start with writing some easy functions to handle my need of the physic part. To be honest, I am not even sure how a physics engine works or how to use one.Thanks again!Eagle.   ;  If you're posting this in the beginners section, you shouldn't even contemplate writing your own. Never have this thought again.Seriously, it's one of the hardest things you can do on a computer and I've seen many seasoned pro's fail when it comes to the nitty gritty (myself included).;Quote:Original post by RubiconIf you're posting this in the beginners section, you shouldn't even contemplate writing your own. Never have this thought again.Seriously, it's one of the hardest things you can do on a computer and I've seen many seasoned pro's fail when it comes to the nitty gritty (myself included).Here's the thing:Quote:In my next game, I would like to calculate the projection of a canonThis doesn't require an engine. It requires some tiny subset of an engine that the OP probably can write on his own. More than that, integrating a whole big physics engine just for this functionality would be massive overkill. I'd say keep it simple and roll your own, as long as you don't plan to add in more complicated simulation in the future.   ;  For a Tower Defense game, I'd say go with rolling your own. The physics that you're going to need aren't incredibly complicated, and you could probably get away with simple sphere/AABB/Plane collision detection, which is reasonably easy to write. Adding a commercial physics engine would just give you an exceptional amount of headaches because it's way too overpowered for your needs. Go with something simple and you'll be able to have a lot more control over fine-tuning the gameplay.When it comes to more complex projects (In my case, an FPS), I asked myself the same question when I started adding physics to the engine that I'm working on. I decided to go with rolling my own physics engine because I liked having the control as well as wanted to learn about physics.In the end, I discovered that the wheel I was trying to reinvent was huge and incredibly complicated. Writing a good, robust collision library is incredibly difficult and finicky (With lots of ugly hacks and nasty little edge-cases), and on top of that I had to write my own toolset for creating and exporting the geometry.So I switched over to Bullet, and then a little later switched over to PhysX (And soon moving over to Havok). The best things I got out of trying to roll my own were:- I got a better understanding of the underlying principles of a physics engine- I gained a lot of respect for the amount of expertise that has gone into the available engines- I managed to write a good, generic physics abstraction that meant that I could switch around physics engines reasonably easily.   