Hi guys.
I'll cut to the chase, I'm not sure how to approach checking if lines intersect with polygons. I would like my game to have enemies with hitboxes made out of polygons (probably mostly rectangles and triangles) and also laser weapons which pass through enemies whilst dealing damage to them.
I figure that there are probably some great libraries already out there for this but I'm not sure which are most suited to this, and I'd kind of like to get a better understanding of how to perform these kind of checks for when I start tackling poly vs poly collision.
Any recommendations or explanations would be much appreciated!
Collision: Polygons and Lines
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Collision: Polygons and Lines
Well, since you mention libraries, here are two I know:
MLib (made by me) and HardOn made by vrld.
I don't know about the latter, but in MLib, here's how you would do it:
You can always read more on the wiki and stuff.
MLib (made by me) and HardOn made by vrld.
I don't know about the latter, but in MLib, here's how you would do it:
Code: Select all
local mlib = require( 'mlib' )
function love.load()
Line = mlib.shape.new( 1, 30, 40, 50 )
Polygon = mlib.shape.new( 10, 10, 10, 20, 20, 20, 20, 10 )
end
function love.draw()
love.graphics.line( Line.x1, Line.y1, Line.x2, Line.y2 )
love.graphics.polygon( 'fill', Polygon.points )
end
function love.update( dt )
mlib.shape.checkCollisions()
end
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot] and 9 guests