Primadawn wrote:You have two problems: (possibly 3)
1. You have to divide all the coordinates by PIXELS_PER_METER (default is 32)
2. You can't set multiple bodies to one sprite, you need to create one complex body. (I can pull out some code for you that does it if you'd like)
3. I think the direction should go clock-wise because the y axis is upside down (I'll verify it later)
Also, you can create this body from 3 vertices, you don't need 5. (P2M = 32.0f)
1. (-62 / P2M, -20 / P2M) (62 / P2M, -20 / P2M) (62 / P2M, 20 / P2M) (-62, 20 / P2M)
2. (-20 / P2M, -62 / P2M) (20 / P2M, -62 / P2M) (20 / P2M, -20 / P2M) (-20 / P2M, -20 / P2M)
3. (-20 / P2M, 20 / P2M) (20 / P2M, 20 / P2M) (20 / P2M, 62 / P2M) (-20 / P2M, 62 / P2M)
bobdebouwer wrote:Why do you need to divide by P2M? I didn't do that with normal bodies (less than 8 vertices) and they seem to work fine.
What units does Box2D use?
Box2D is tuned for meters-kilograms-seconds (MKS). Your moving objects should be between 0.1 - 10 meters. Do not use pixels as units! You will get a jittery simulation.
How do I convert pixels to meters?
Suppose you have a sprite for a character that is 100x100 pixels. You decide to use a scaling factor that is 0.01. This will make the character physics box 1m x 1m. So go make a physics box that is 1x1. Now suppose the character starts out at pixel coordinate (345,679). So position the physics box at (3.45,6.79). Now simulate the physics world. Suppose the character physics box moves to (2.31,4.98), so move your character sprite to pixel coordinates (231,498). Now the only tricky part is choosing a scaling factor. This really depends on your game. You should try to get your moving objects in the range 0.1 - 10 meters, with 1 meter being the sweet spot.
An example of a complex body would be helpful.
Why do you need to divide by P2M? I didn't do that with normal bodies (less than 8 vertices) and they seem to work fine.
Primadawn wrote:Like I said in point 3 of my first post, the vertices have to be created in a clock-wise direction!
Yours are anti-clock-wise.
Use the vertices I gave in the code example, they will do exactly what you want.
Users browsing this forum: Google [Bot] and 7 guests