Android Question polygons collision detect - libgdx

ilan

Expert
Licensed User
Longtime User
Hi

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
 

ilan

Expert
Licensed User
Longtime 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??
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
thank you informatix, i didnot knew you have uploaded new examples, they are great.

o_O They exist since the first version.

now i would like to move the body, so i need to set it to Bullet = ture to be able to move it??
Bullet=true is for small, fast moving bodies that can collide with another dynamic body. It enables the Continuous Collision Detection mode.

i tried everything but i could not move it, this is the first time i use Box2D bodies so sorry for my ignorance
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.

do i need to set a World everytime i use Box2D Bodies in an App?
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: http://www.iforce2d.net/b2dtut/
 
Upvote 0
Top