I’m making a 2d collision module and got almost everything working, except for the hitbox offset.
I’m using this function to calculate the hitbox:
function CollisionService:GetEllipseVertices(Ellipse)
local Vertices = {}
local Position = Ellipse.AbsolutePosition
local Size = Ellipse.AbsoluteSize
local Rotation = Ellipse.AbsoluteRotation
local Center = Position + Vector2.new(0, Size.Y) + GuiService:GetGuiInset()
local InnerHitbox = false
for angle = 0, math.pi/2, math.pi/16 do
local X = Size.X * -math.cos(angle)
local Y = Size.Y * -math.sin(angle)
local RotatedX = X * math.cos(Rotation) - Y * math.sin(Rotation)
local RotatedY = X * math.sin(Rotation) + Y * math.cos(Rotation)
local Vertex = (Center + Vector2.new(-RotatedX, RotatedY))
if not InnerHitbox then
InnerHitbox = true
Make(Vertex + Vector2.new(RotatedX, -RotatedY), Ellipse.Parent)
table.insert(Vertices, Vertex + Vector2.new(RotatedX, -RotatedY))
end
Make(Vertex, Ellipse.Parent)
table.insert(Vertices, Vertex)
end
return Vertices
end
That’s how the hitbox look like:
https://i.gyazo.com/374716a6fbd330fba44a127a2927584d.gif
The hitbox position is only being offsetted when the object is rotated. Any help is appreciatted