Category Archives: Box2D

Tracking Missile in Box2D

If you have been playing around with Box2D then chances are you have already figured out how to simulate linear projectile motion or maybe even tried to simulate arrow flight. These are all great places to start, but maybe you are looking for something more advanced? How about a projectile that scans for targets and when it has locked on to one follows it to the bitter end? Continue reading Tracking Missile in Box2D

Simulating Multiple Sources of Gravity in Box2D

Simulating a single source of gravity is a sinch in  Box2D. You can even switch gravity off if you like. But what about simulating multiple gravity sources, like planets? This isn’t as hard as it sounds, but requires some additional work. Something to consider is that when simulating radial gravity, or planet gravity, we don’t work with the same scales as in, um, the universe. Instead of orbits that are thousands kilometers we’re working with ten to fifty meters, depending on the canvas size and pixel to meter ratio you are using. Continue reading Simulating Multiple Sources of Gravity in Box2D

Buoyancy in Box2D – Multiple Pools

An earlier post covered the basics of using the buoyancy controller in Box2D. In that example there was one buoyancy controller and all bodies were added to it by default. But you may want control when a body is added to a buoyancy controller, for example if your player is jumping into or out of a body of water. You may even have different water obstacle at different vertical positions in your game. This post shows you how to manage multiple buoyancy controllers and how to determine when to add or remove bodies to them. Continue reading Buoyancy in Box2D – Multiple Pools

Buoyancy in Box2D – The Basics

Who doesn’t like playing with water? There’s something childishly enjoyable about watching objects bobbing around on the surface or horror of something quickly sinking in to the the dark abyss. Box2D makes simulating buoyancy  simple with help of the b2BuoyancyController. But keep in mind, this Box2D only simulates buoyancy not all the a liquid, so don’t expect it to make waves. That is some magic you will need to work out yourself.  Continue reading Buoyancy in Box2D – The Basics