Jump to content

changing offset of a p2 shape without reapplying the whole shape?


valueerror
 Share

Recommended Posts

Did you looked into body's shapeOffsets?

    /**     * The local shape offsets, relative to the body center of mass. This is an     * array of Array.     * @property shapeOffsets     * @type {Array}     */    this.shapeOffsets = [];

I started to look into Phaser's source, there you'll find lot of answers in general.

Link to comment
Share on other sites

"shapeOffsets" is an array of points which describes each shape's offset from the sprite, as far as I know.

// pseudo codeshapeOffsets = [[shape1_x, shape1_y], [shape2_x, shape2_y]];

When you want to change the shape's offset without creating new geometry you need to change these offsets, imho.

Otherwise just ask @schteppe, he's the creator of P2.js.

Link to comment
Share on other sites

  • 2 months later...

As far as I can tell, you need to supply shapeOffsets with a p2 vec2, and you may need to update the AABB and bounding radius after you change the offset. I haven't tested this myself, but this should be the correct way:

 

var myOffset = p2.vec2.fromValues(-1, -1); // this creates a vector that points 20 px to the right and 20 px downp2body.shapeOffsets[0] = myOffset; // this assigns the vector to the first shape's shapeOffset. note that this is a property of the p2body (so phaserbody.data)p2body.updateAABB();p2body.updateBoundingRadius();
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...