Jump to content

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


valueerror
 Share

Recommended Posts

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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