Not likely, my world boundry is different than the boxes extents:
ERIN:
Sure..just look at your HelloWorld example 😉 . My code is identical to it. The only difference is that I'm calling Step() in my logic loop which runs at a speed of 200 loops per second, and my drawing function is called when the logic loop tells it to (every x logic loops). Also, all the values in box2d that I'm passing to define things, are all in terms of pixels in my application. So a box with extends 20 by 20 will be drawn as a 40 by 40 box and a world that is defined as 100 by 100 will be 100 pixels by 100 pixels, etc . Maybe that is the problem?
Since you scaled things up you also need to scale up gravity. You also need to make the world AABB huge, like 10000 x 10000. If something hits the world AABB (including ground), it will be frozen and stop colliding.
People often run into trouble when they use pixel dimensions. Consider using some sort of display transform so that you can use meters for Box2D dimensions. This is how the testbed works.
So maybe something like:
1 - Convert World AABB width and height (meters) into the screen width and height (pixels)
2 - Convert all shapes/objects/bodies demensions into pixels related to the screen demensions
3 - Have a working program?
Lemme try this...
Well don't use the screen dimensions. Use a scale similar to the test bed examples. So a typical game object is between 0.1 and 2 meters in size. For example, a humanoid character would be about 1.7 meters tall.
So an example of that would be:
- 1 pixel = 1 meter
- So 5 pixels = 5 meters
Than to correct my last post:
1 - Convert all shapes/bodies/objects/etc dimensions into pixel dimensions
2 - Draw to screen
3 - Have a working program..
Alright, now I'll try it.
So I eliminated all the calculations to transform the world dimensions into the screen dimensions, but now I'm just back to where I started. The dynamic box simply falls until its y-position is equal to its y-extend. Here are some things I'm doing in my program that might help you figure this out:
- The scale is: 1 pixel = 1 meter
- worldAABB dimensions are: min(0,0) max(1024,768)
- dynamic box dimensions are 50 x 50 with extends 25 x 25
- static box dimensions are 50 x 50 with extends 25 x 25
- dynamic box is placed at 0 , 0
- static box is placed at 0 , 718
Also, the dynamic box isn't effected by gravity when I change the initial x position. It has to start with an x position of something around less than 10. ❓
Erin was suggesting you use meter units not as 1 pixel = 1 meter, but 1 unit = 1 meter, you should scale the values so 1 meter becomes 30 pixels or so when you render, but this should be decoupled from the physics simulation.
I'm not sure if a body will sleep if it's partially outside the world or not, but if you place the box at 0,0 then it will be 3/4 out of the world AABB, which might cause it to start asleep?
The world AABB shouldn't be only as big as the screen anyway, make it as big as you need it to be (say -100,-100 to 100,100 meters).
Another thing, if you're using a y-down world, you will need to make the gravity a positive y value also, otherwise bodies will fall 'up' until their y extent (when the top of the box hits the top of the world (or the bottom of the box leaves the world, not sure which one)), as you said was happening before.
If that doesn't help, could you post some code so we can try to reproduce the problem?
-Matt
Hmm, so I reset the dynamic boxes position, and my gravity was already set to 10. Anyway, now the box doesn't move at all. When I run the program, nothing moves or happens. ❓