Beginner Questions

Hi, I'm only just starting with Box2D (liquidfun to be precise) and would like to know


- what shape should I use for a player character? After working with NVidia Physics I would go with a capsule, but there aren't any in Box2D 🙁

- what shapes should I use for a terraria-like world that is made of regular squares? I read that adjacent boxes will cause collisions with internal vertices.
You can create a capsule by creating a box and two circle fixtures within the same body. But it obviously depends on the interaction you want between character and environment. For example, by default a capsule would tend to topple over.

If your terrain is static, then I'd imagine the most efficient way would be to calculate the surface contour and then use one or more b2ChainShapes for it.
The terrain is static, but changes shape (squares added/removed) frequently. So I think it's hard to try and update the optimal shape without any "redundant" vertices over and over in real-time.

If I use a chain shape and only leave out the internal edges (the ones covered by neighboring squares), but still use edges of one square's length put next to each other on a flat surface - will I get the same kind of "ghost collisions" as with boxes put together? That would be a problem... I'd like to use lots of very small chains, or maybe just single edges, in my case to keep it flexible for quick manipulation.

I mean, I'm hoping that the problem is caused only by the vertical edges.
Using a chain shape (or individual edge shapes with previous/next vertices) will solve the problem of ghost collisions that you would have using square polygons. Both will require you to maintain some information about the surface contour however, since you need to be able to specify the vertices in order (or in the case of individual edges, you need to know which vertices precede and succeed your edge on the surface).

It shouldn't be too hard to come up with a data structure for this, that you can maintain as you add and remove squares, so you don't need to determine the contour from scratch every frame.
Thanks, that's reassuring. Now I only need to understand what exactly these next vertices are supposed to be in the case of individual edges. My edges will (probably quite normal) share a vertex with each neighboring edge, although that vertex will probably be double, once for each edge. Which ones are next then? The ones behind the double vertices or the doubles themselves?
Excuse dodgy ascii drawing, and assume a horizontal edge across the top. The trailing section is made up of 2 square widths.

_||__

So left to right you have 7 vertices (A-G), 6 edges.

For a chain shape you'd just pass the 7 in order, and it will do the rest.

To use individual edge shapes, you create the following edges, explicitly setting the prev/next vertices (in parentheses). The first vertex will have no previous, and the last no next.

()AB(C) - across
(A)BC(D) - up
(B)CD(E) - across
(C)DE(F) - down
(D)EF(G) - across
(E)FG() - across
Ok, thanks again! I think it's clear now. So, basically with (almost) every edge I really define three edges. Looks like I should be able to update edges per square easily only by checking the directly adjacent squares (solid/empty) and then either have an extended edge reach out to the next square or keep it inside.
I've got another beginner question: what's the best method to test a point (or shape) in world-space for (any!) overlapping shapes? Like a raycast. In the documentation I only found a way to test a single shape for an overlap like this.
So I am using world.queryAABB with a custom callback now and it does what it should.
Is there a maximum velocity somehow?...

I wanted to create fast moving projectiles, but they don't get any faster, no matter what linear velocity I set in the body descriptor - like it's capped.

I also noticed that projectiles keep flying in their direction when gravity is turned off. With gravity, the initial velocity is gradually lost and after a while the velocity vector points completely in the direction of gravity. So clearly, there has to be a velocity cap. Can't I turn this off? I use no damping.


Hmm.. ok I adjusted the scaling for objects of 0.1-10 size and it's probably neglectable now.

Original thread: https://box2d.org/forum/viewtopic.php?t=9965