Can't the collider box itself be rotated?

rotate

Hi guys.
I'm making some sort of laser beam.
However, the size of the collider box depends on the rotation angle.
Is there any way to rotate the collider box itself like a sprite?
please help.

Interesting example.

non-aligned bounding box makes collision code more complicated.

You might try alternative approaches:

line through circle

  1. loop through each enemy and see if their circle overlaps the laser line
  2. you'd need to represent the laser line in code as well as in a sprite

point on line

  1. loop through each enemy and see if their position is on the laser line
  2. you'd need to represent the laser line in code as well as in a sprite

two stage checks

  1. Check collision is in bounding box
  2. Check certain pixels underneath enemy to see if it is over laser

multiple collision boxes

  1. split the laser collider into multiple smaller collider boxes
3 Likes

Just to confirm, the collision system only handles axis-aligned bounding box (AABB) collisions, so you cannot rotate the collision box.

For this example, I would see if playdate.graphics.sprite.querySpritesAlongLine() would work for what you need. Instead of making the laser a colliding sprite, you would define the line you pass to that method based on the start and end points of your laser beam, and it will return any sprites that the line intersects.

querySpriteInfoAlongLine() is also an option if you want even more info about the collisions, such as entry and exit points and how far from the laser's starting point the collision occurs. Take a look at the collisions example code in Examples/Single File Examples to see that in action.

3 Likes

thanks matt, l'll check it.

thanks dan, I'll check "querySpritesAlongLine".

1 Like