i have a plattform with an enemy on top and i want him to move arround without falling from it, what is the best way to detect when he is getting both corners?
Your question is vague. Do you want the enemy to move on the platform or do you want the platform to move with the enemy on it?
i want my enemy body to walk left and right on a plattform without falling.
Assuming you want the enemy to remain entirely on the platform (that is, not to hang over the edge), the enemy should not be allowed to go any farther left than the left edge of the platform plus half the enemy’s width, and should not be allowed to go any farther right than the right edge of the platform minus half the enemy’s width. Pseudocode (no guarantee of correctness):
float extent = enemy.width / 2;
enemy.x = clamp(enemy.x, plaform.left + extent, platform.right - extent);
There are of course other considerations, such as how the enemy will move and so on, but the above at least addresses the specific question of how to constrain the enemy to the platform.
you are right :P, i´ll try to explain it better… i´m working in a plattformer with libgdx and box2d, the thing is that i want to have some enemies on plattforms walking left and right, i´m using tiled to do the maps and a enemy layer with some objects there to have a reference to drop my enemies on top of the plattforms, the thing is that i´m getting my contact listener between them but i can figure out how to get the contact x point related to my plattform. I keep a reference of the plattform on my enemy to have the with of it but i need to know when he rise the edge…does it have to be something with te world manifold and the overlap? ???