Search code examples
libgdxpolygongame-physics

LibGDX Hitbox / Polygonshape and Physics


Hello I have two smaller questions:

Is it possible to map the Shape of the Body 1:1 to the texture so I have a perfect collision detection ? Because right now I only know of two ways to do it: Create the Shape before and load it up with a texture or load the texture first and then set the shape as a box ... But that is too simple I think.

Also does anyone know how I can turn off the physics of the world ? When Body A hits Body B I want the Body to do a certain animation and fall to the ground with some sound effects, but when the two objects collide they bounce off each other in different directions etc. When two objects collide I want it to be "Game over" basically and stop calculating momentum etc.

I dont care about the solution itself, just telling me if its possible at all for both questions would be enough.


Solution

  • I guess you are using Box2d

    Is it possible to map the Shape of the Body 1:1 to the texture so I have a perfect collision detection ?

    It possible, you can use PolygonShape in Box2D, but it has to be a convex polygon. Furthermore it slower then predefined shapes.

    Also does anyone know how I can turn off the physics of the world ?

    With box2d Physics you can simply stop the simulation on your own by not executing the world.step() command