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
5 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.

5 Likes

thanks matt, l'll check it.

thanks dan, I'll check "querySpritesAlongLine".

1 Like

@dan thank you for the suggestion. I was trying to rotate a rect and along with it, a collider rect, but as it's not possible. How would i say use playdate.graphics.sprite.querySpritesAlongLine() for a line with width 32px (which is the width of my rect)?

you would simply check the line, and for the width you could do a second check to see if distance from the closest on the line is less than half its thickness.

https://sdk.play.date/inside-playdate/#m-geometry.lineSegment.closestPointOnLineToPoint

Following this post I have been trying to use querySpriteInfoAlongLine() but I am not getting it to work, I think I am misunderstanding something. The problem is that the method says the lineSegment I pass to it is not found although it exists.

The code:

print("lineSegment = ", self.collider.x1, self.collider.y1, self.collider.x2, self.collider.y2)
local what = self:querySpriteInfoAlongLine(self.collider)

The debug log output:

lineSegment = 	215.0	120.0	245.0	120.0

Update error: bar.lua:47: playdate.geometry.lineSegment or x1, x2, y1, y2 values not found.
stack traceback:
	[C]: in method 'querySpriteInfoAlongLine'

Ok, I leave here the answer. The call to this method should be:
local tableOfCollidedSprites = gfx.sprite.querySpritesAlongLine(self.foreHandLineCollider)

I am new to lua and playdateSDK, so I am not quite sure why it failed before, I believe it is because it is not object related but a static method.

Edit:
Ok, I just realised: In docs there are methods (highlighted with an 'M') and functions (highlighted with an 'F'), querySpritesAlongLine is a function so you can not reference it from your object but directly as 'gfx.sprite.querySpritesAlongLine'