I am looking for a way to move an object like a rectangle by keyboard that has another object placed on top of it. I want to control the movements of the bottom object while the upper object should balance on it and therefore follow its movements. It should fall down when the bottom object is tilting.
Using ofxBox2d the upper object does not move until the bottom one is almost gone, then it falls off. I move the object by setting its position. When I move the object by using force, it is collapsing. I also thought that the friction might be relevant but this doesn’t seem to be the case. I tried to illustrate my problem in the following image:
What am I missing? Is there a proper way to do this? Or another library?
You need to set the green rect’s friction large enough so that it doesn’t slip off from the black rect. Also you should use addForce(...) since setPosition(...) won’t be affected by friction.