Android Question polygons collision detect - libgdx

Discussion in 'Android Questions' started by ilan, Jul 29, 2015.

  1. ilan

    ilan Expert Licensed User


    Does anyone know how to work with polygons bodies box2d in libgdx?

    i would like to create 2 polygons bodies and check if they collides...

    A source example would be great...

    Thank you
  2. Informatix

    Informatix Expert Licensed User

    There are many Box2D examples provided with libGDX.
  3. ilan

    ilan Expert Licensed User

    thank you informatix, i didnot knew you have uploaded new examples, they are great.

    i have tried the example: Box2D_PysicsBodyEditLoader and i could load my bodies i created with the Body Editor

    now i would like to move the body, so i need to set it to Bullet = ture to be able to move it??
    i tried everything but i could not move it, this is the first time i use Box2D bodies so sorry for my ignorance

    i try it like this: Bodies(i).Position.x = Bodies(i).Position.x + 5
    but the body is not moving, i see that every frame there is a sub that update the sprites to the bodies position so the image should move with the body but nothing happens...

    i check also in the logs and the body x/y is the same...

    do i need to set a World everytime i use Box2D Bodies in an App?

    is it possible just to load Box2D bodies to my game and start move them around and check for collisions between them only??
  4. Informatix

    Informatix Expert Licensed User

    o_O They exist since the first version.

    Bullet=true is for small, fast moving bodies that can collide with another dynamic body. It enables the Continuous Collision Detection mode.

    To set a position and an angle, you have to use SetTransform. But to detect a collision, Box2D needs another data: the force applied to the body (with no velocity, the body is supposed to be static). You can pass the force returned by Steering Behaviors. You can also use Box2D to compute your moves. Usually, I use only Steering Behaviors to select the next path and initiate the move, everything else is managed by Box2D.

    Yes, it's mandatory because it's where the simulation takes place. If your game uses a top-down view, you have to set the world gravity to 0.
    You will find a lot of resources on Internet to explain how Box2D works and how to use it, with great examples. For example:
  5. ilan

    ilan Expert Licensed User

    thank you informatix, i will check those examples...

    i had Examples_Templates_1_03 and yesterday i downloaded Examples_Templates_1_08 .. (they are the same?! :confused:)
  6. Informatix

    Informatix Expert Licensed User

    I don't think I changed something in Box2D examples between these two versions but it is recommended to download the latest examples anyway.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice