7
\$\begingroup\$

How can top view physics games be done in box2D? One idea I have is to set the linear velocity of an object manually or to alter the linear and angular damping as my object moves over different surfaces. For example if my object is over a wet surface it'll have less linear damping and if it is over rough surface it'll have more damping. And to see if my object has fallen over an edge I'll try to use an AABB and check if its still inside or manually see if object.x > boundary.x etc. Is there any better way?

\$\endgroup\$

4 Answers 4

5
\$\begingroup\$

Look into b2FrictionJoint to simulate top-down "rough surfaces". Motion damping doesn't end up looking that realistic.

You can basically attach your objects to anything using a friction joint to get it to work. (I attach them all to a floor object, but it doesn't matter how big or where it is.)

\$\endgroup\$
3
\$\begingroup\$

If you simply set gravity to zero then the physics simulation works well for a top-down game.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Disabling gravitiy doesn't turn Box2D into a top-down physics simulation. How would you simulate ground friction? What about a car that drives through mud? \$\endgroup\$
    – bummzack
    Jun 24, 2011 at 7:03
  • \$\begingroup\$ I would do that by changing the car's density or friction or something using sensors for the mud area. Admittedly that's semantically hacky because that's not the intended purpose of those features, but it's a simple way to keep having Box2D do all the work for you. \$\endgroup\$
    – jhocking
    Jun 24, 2011 at 12:18
1
\$\begingroup\$

Box2D is designed to work with two-dimensional space. On a 2D platformer game we could describe our objects with a basis XY:

--------- X
|
|
|
Y

In this game there is no depth, ok? If we want see this same game with a top view, our space need a third new dimension Z, to describe depth. What happens? Now we have three dimensions but Box2D is designed in two dimensions.

The game can be visually two-dimensional, but the logic is three-dimensional in this case. ( top-view ).

I think that will be better use another 3D physics library, or implement one yourself.

I never have seen a top view game using Box2D and I would be very grateful if someone knows one.

\$\endgroup\$
7
  • 2
    \$\begingroup\$ I disagree that the "logic" would necessarily be 3D. For a 2D game, Z is usually just the order in which objects are drawn for visual purposes. This doesn't need to be simulated or tied to the physics at all. \$\endgroup\$ Mar 7, 2011 at 17:26
  • \$\begingroup\$ I've said that in "this case" we need a logic three-dimensional.The Z that you said is not a new dimension, it's only a form to describe the relative order in that the sprites must be drawed. ( painter algorithm ) \$\endgroup\$
    – momboco
    Mar 7, 2011 at 17:35
  • \$\begingroup\$ In Box2D the Y coordinate is the altitude ( and that to which the gravity is applied ). I don't know how to change this if you want a game with top-view. Because if you use gravity, then you loose a dimension and it's needed a third dimension. \$\endgroup\$
    – momboco
    Mar 7, 2011 at 17:39
  • 3
    \$\begingroup\$ Here is a top-down game that uses Box2D: sevengames.com/nitro-racers. I happen to know this because I helped program it :P The vehicle movements are a bit hacky, with manual setting of the rotation, and friction over grass is also done manually, but the rest (acceleration, bumping & bouncing, collision with the environment) is pure Box2D. \$\endgroup\$ Mar 7, 2011 at 21:59
  • \$\begingroup\$ Thanks a lot. I have some questions. The collision with the environment only produces that the car stops. Do you think that the rebound can be acomplished with Box2D? The friction over the grass is manually implemented due to some limitation of Box2D? When I've developed games with top-view sometimes I've used 3d logic with z for altitude, and then associate this value to a scale ( for example, a casing that is launched from a pistol). With Box2D I have not found how to deal with this. \$\endgroup\$
    – momboco
    Mar 7, 2011 at 22:40
0
\$\begingroup\$

As jhocking said, its the same using Box2D for a side or top view.

Just disable gravity and play with depths using the colision filtering in the box2D manual.

because there will be no gravity force, the objects will be "lighter" than normal, when pushing them. Play with the masses and the forces to achieve equivalent results.

What you refered to as damping, should be the common friction in Box2D, i think. and as for checking limits of your levels, there are sensors. shapes that will tell you when something passes over :)

\$\endgroup\$
2
  • 2
    \$\begingroup\$ "because there will be no gravity force, the objects will be "lighter" than normal, when pushing them": Why? Their mass hasn't changed just because gravity is missing. \$\endgroup\$
    – alxx
    Apr 30, 2011 at 17:56
  • 1
    \$\begingroup\$ Their mass wont change. But gravity will no longer hold them to the ground, so when they are not touching a surface, they will be easier to move. \$\endgroup\$ May 9, 2011 at 18:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .