Jump to content

Resizing tileSprite overlap detection


Zekko
 Share

Recommended Posts

I'm trying to figure out how to best detect overlap between a tileSprite that's resizing and relocating every frame (I use it to visualize a physics spring) and a group of sprites with circular P2 bodies attached (in order to remove the spring upon contact).

 

I tried attaching a P2 body to the tileSprite (spring) and call body.setRectangleFromSprite() every frame like so:

spring.body.x = x;spring.body.y = y;spring.width = width;spring.body.angle = angle;spring.body.setRectangleFromSprite();

...and was planning to enable the body's data.shapes[0].sensor for overlap detection as described here: http://www.html5gamedevs.com/topic/5567-trigger-with-p2/

 

However, for some reason the body's angle is different from the sprite's angle (see attached images) (I'm ignoring the body's offset for now). The body appears close to perpendicular to the sprite when the sprite is almost vertical, while the body almost matches the angle when the sprite is close to horizontal. Math has always been my Achilles' heel, but this smells like a sine/cosine problem to me.

 

Am I doing something wrong? Or is there an altogether better way of going about this? Many thanks in advance to this wonderful community!

post-12519-0-93545700-1420903632.png

post-12519-0-24236300-1420903633.png

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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