Collision library that take rotation in to account
Posted: Mon Aug 28, 2023 9:30 am
Hi all!
I am looking for a collision library that also take rotation in to account. For now I only need rectangle shape.
Yes I can see there is lot of discussions on the forum about this that usually end with recommending the HardonCollider library:
https://github.com/vrld/HC
However, my problem with this library is that there is a conflict when I want to rotate and move the collider at the same time.
The problem is that the rotation command uses the center point to rotate the collider and the top left corner to position it. While the move command uses the center point to position the collider and it is create a conflict between the two commands when used same time. The move command essentially override the rotate command positioning.
The problem with this is that my sprites are rotating around the origin point and position of origin can be anywhere I want to. I can make the collider rotate or move with my sprites but I can not make it rotate and move same time because the library handle this 2 different ways.
Setting the position of the collider box directly using obj._pos.x and obj._pos.y instead of using the move command is not working but I have no idea why.
The library is not documented and it uses abstraction on top of abstraction on top of abstraction, I can't figure out how it works and not even Visual Studio Code is able to find definitions of the methods. Why on earth someone didn't think of moving and rotating a collider at the same time using the same position is beyond me.
So apart from HardonCollider is there any other collision library I can try?
Or would anyone have any idea how to make :moveTo() and :setRotation() work together in HardonCollider?
To be honest I don't even understand how :setRotation() works because the method accept x,y as arguments and pass it on to an other rotate method and it is offset the position of rotation
But if I go to the definition of the rotate command, it doesn't do anything with position, it doesn't even accept position as argument:
There has to be an other implementation but I can't find it where it is.
And the moveTo() method for whatever reason subtract the center position from the actual position:
I have no idea why is it need to take in to account the center position at all but if I remove it, it doesn't work and VS code can't find the definition of :move()
The only thing I can find is this:
But this is not the one the rectangle is using.
I simply can't find the move() and rotate() method used by the rectangle.
I spent the last 2 days trying to figure this out, but I can't.
I would appreciate any help.
Thank you.
I am looking for a collision library that also take rotation in to account. For now I only need rectangle shape.
Yes I can see there is lot of discussions on the forum about this that usually end with recommending the HardonCollider library:
https://github.com/vrld/HC
However, my problem with this library is that there is a conflict when I want to rotate and move the collider at the same time.
The problem is that the rotation command uses the center point to rotate the collider and the top left corner to position it. While the move command uses the center point to position the collider and it is create a conflict between the two commands when used same time. The move command essentially override the rotate command positioning.
The problem with this is that my sprites are rotating around the origin point and position of origin can be anywhere I want to. I can make the collider rotate or move with my sprites but I can not make it rotate and move same time because the library handle this 2 different ways.
Setting the position of the collider box directly using obj._pos.x and obj._pos.y instead of using the move command is not working but I have no idea why.
The library is not documented and it uses abstraction on top of abstraction on top of abstraction, I can't figure out how it works and not even Visual Studio Code is able to find definitions of the methods. Why on earth someone didn't think of moving and rotating a collider at the same time using the same position is beyond me.
So apart from HardonCollider is there any other collision library I can try?
Or would anyone have any idea how to make :moveTo() and :setRotation() work together in HardonCollider?
To be honest I don't even understand how :setRotation() works because the method accept x,y as arguments and pass it on to an other rotate method and it is offset the position of rotation
Code: Select all
function Shape:setRotation(angle, x,y)
return self:rotate(angle - self._rotation, x,y)
end
Code: Select all
function Shape:rotate(angle)
self._rotation = self._rotation + angle
end
And the moveTo() method for whatever reason subtract the center position from the actual position:
Code: Select all
function Shape:moveTo(x,y)
local cx,cy = self:center()
self:move(x - cx,y - cy)
end
The only thing I can find is this:
Code: Select all
function PointShape:move(x,y)
self._pos.x = self._pos.x + x
self._pos.y = self._pos.y + y
end
I simply can't find the move() and rotate() method used by the rectangle.
I spent the last 2 days trying to figure this out, but I can't.
I would appreciate any help.
Thank you.