Collision checking on angled sprite not working

DavidTaylor.8310DavidTaylor.8310 David TaylorUSMember

I have a entities that goes from the top left to the bottom right. The entities have a sprite that is just a black block. When the block collides with another block I set its velocity to 0. When checking collisions for the sprite it works fine but when I set the sprites rotation or use CCRotateBy the collision still stops where it would have had it not been angled. I am using the BoundingBoxTransformedToWorld to check for intersection. Why is this not working?

public bool Intersects(Vehicle other)
{
return this.sprite.BoundingBoxTransformedToWorld.IntersectsRect(other.sprite.BoundingBoxTransformedToWorld);
}


Best Answer

  • DavidTaylor.8310DavidTaylor.8310 David Taylor USMember
    Accepted Answer

    Nevermind, after doing some research it turns out that rotating a sprite creates a bounding box with a maxX,maxY,minX,minY so it essentials draws a bigger box with 0 rotation around the rotated rectangle

    Looking into box2d it looks like they have an IsTouching() method on b2Contact but I can't figure out an easy way to just use that for collisions yet.

    Is this really such a strange feature to expect?

Answers

  • DavidTaylor.8310DavidTaylor.8310 David Taylor USMember
    Accepted Answer

    Nevermind, after doing some research it turns out that rotating a sprite creates a bounding box with a maxX,maxY,minX,minY so it essentials draws a bigger box with 0 rotation around the rotated rectangle

    Looking into box2d it looks like they have an IsTouching() method on b2Contact but I can't figure out an easy way to just use that for collisions yet.

    Is this really such a strange feature to expect?

Sign In or Register to comment.