Hi, I'm in the process of writing an Android game, and I need just a little bit of help with some physics. I do not wish to implement an entire physics engine, as, 1) I have already tried the Java port of Box2D on an Android device, and there is a huge garbage collection problem, and 2) I don't think my problem is complex enough to need a physics engine.

Anyways, let me describe what I want to do with a picture:
http://i189.photobucket.com/albums/z266/Capn_Soul/BasicPhysics.png

Basically, I have some boxes fall from the top of the screen that, when they collide with an object, they stop falling and stack up (as shown in the picture). But rather than the boxes just sitting there and doing nothing, I want boxes to abide by the rules of basic physics. For example, I would like the light blue box on the top of the stack to tilt and fall off to the right. How would I accomplish this?

If anybody could point me to a place where I could learn the physics necessary to do this, I would really appreciate it. I have found a few tutorials about 2D physics, but they all seem to use spheres in their explanations and examples.

Thanks so much in advance.

You could try here: http://chrishecker.com/Rigid_Body_Dynamics

I've never done this, but my intuition would be this. Gravity is applying a downward acceleration on the box; this amounts to a force applied directly downwards starting from the object's centre of gravity (for a box, this is just the centre). You can calculate how far the box is over the edge; if the centre of gravity is resting on something, the box won't tilt.

If the middle of the box is above thin air, then you have an upward force applied by the box underneath it; this force will contribute to keeping the box in place but it will also contribute to the box's angular (rotational) velocity. Basically the portion of the upwards force vector that is perpendicular to the vector between the point of contact and the centre of gravity will contribute to angular velocity.

That sounded confusing . . . I tried to draw a picture but it didn't work out so well. I may give it another shot later. Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.