Pages

Tuesday, June 21, 2011

Physics Bodies in AndEngine

If you have already experimented with the physics example of andengineexamples, then you should already know that you need to create physics bodies to be able to interact with the physics world.
But maybe there are some things that are not immediately obvious about these physics bodies, such as :
  1. Types of physics bodies and their properties.
    Static body : has zero mass, zero velocity, but can be moved manually. Static bodies do not collide with other static or kinematic bodies.

    Kinematic body : has zero mass, but has a velocity set by the user. Kinematic bodies do not collide with other static or kinematic bodies.

    Dynamic body : mass and velocity can be set by the user, and respond to physics forces, but you can also move the body manually. Dynamic bodies can collide with all body types.

    So, if you want a body that does not respond to physics forces, but you want that body to collide with other bodies, then you should create a dynamic body, set gravity to zero, then move it manually.
  2. Unit of measurement used to manipulate a physics body location.
    In manipulating physics body location, the unit used is not pixel but meter.
    When you create a body, you can control the pixel to meter ratio using the pPixelToMeterRatio variable.
    This variable has a default value of 32(PIXEL_TO_METER_RATIO_DEFAULT).
    This means that if you didn't change the default value, if you use .setTransform(new Vector2(1, 1), 0) on a body, you will put that body in coordinate (32, 32).
I think that's all I can think of right now, if I remember something else I will add it later.

    1 comment:

    1. hi I am newbe for andengine and i am working on Physics

      I am trying to transform the body onTouch

      body.setTransform(new Vector(getX/32,getY/32),0);
      but when i am touching on screen than body disappears
      any suggestion please ??????

      ReplyDelete