Search code examples
game-engine

How to implement a 2D fair clamp in a game/physics engine?


I've recently played Nintendo Badge Arcade and I wondered how is the clamp implemented.

The expected behavior, for those who don't know the game can be seen in this video: http://ytcropper.com/cropped/2-59b6b68872036

I know the items the player can obtain follow the basic physics of any game engine (they have their gravity, their weight, and its shape is related to its sprite) but I don't know how to implement the clamp.

My first question is: What is the ideal game framework to achieve this. Game maker, box 2d...

And my second and most important question is: How is the clamp implemented. Is it a composite object that rotates both bodies until they touch something and then friction comes in?

Thank you.


Solution

  • One way to go is use Box2D and its Revolute joint to simulate a clamp. Basically clamp is 3 dynamic bodies: hull, and two side bodies that are marked as "ghost" for the hull (so that they do not collide). Joints connecting those bodies to hull must be configured to rotate in the right direction and only when a player performs an action. When a prize is hit by clamp you keep them joints working for body not to fall down thanks to mentioned friction.

    More detailed information can be found in box2d tutorials, I hope the idea is clear.