• Collision Detected [Lua + Löve]
    10 replies, posted
Hey I posted this question a while about in the "What do you need help with" thread but i got no response, so i hope you don't mind if i ask here. I'm having alot of trouble with collision detection with Lua + löve, i know there are things like this [url]http://love2d.org/wiki/HardonCollider[/url] but I'm unsure on how to make it check collisions if there alot of objects. the furthest i get is between two objects, if i can get this working i can actually start making some games haha, thanks. Here is my best shot... [url]http://dl.dropbox.com/u/15805077/perma/Blocks.zip[/url]
So.. what exactly is your question or problem? Your little game seems to be working fine.
I suggest you don't rely on a library that much but instead do your own collision detection and actually understand what's going on under the hood: [url]http://www.metanetsoftware.com/technique/tutorialA.html[/url] I am currently on the way to reproduce this method by purely using vectors, but damn it's complicated shit. I'd suggest you get box-on-box-collision working first. If you want to see my rather modest try at implementing it, you can check out my sourcecode: [url]http://dl.dropbox.com/u/28079852/PlatformerProto14.5.love[/url] (just rename it to .zip and unzip it)
[QUOTE=Bambo.;30125283][url]http://love2d.org/wiki/HardonCollider[/url][/QUOTE] ... HardonCollider? :raise:
[QUOTE=ief014;30128835]... HardonCollider? :raise:[/QUOTE] I'm guessing you haven't looked at many Love libraries. [url]http://love2d.org/wiki/Category:Libraries[/url] :v:
[QUOTE=BlkDucky;30128848]I'm guessing you haven't looked at many Love libraries. [url]http://love2d.org/wiki/Category:Libraries[/url] :v:[/QUOTE] Wow never noticed that.
This is the best I can do really [code] function CheckCollision(box1x, box1y, box1w, box1h, box2x, box2y, box2w, box2h) if box1x > box2x + box2w - 1 or -- Is box1 on the right side of box2? box1y > box2y + box2h - 1 or -- Is box1 under box2? box2x > box1x + box1w - 1 or -- Is box2 on the right side of box1? box2y > box1y + box1h - 1 -- Is b2 under b1? then return false else return true end end for k,v in ipairs(mobs) do v.pos.x = v.pos.x + 1 if CheckCollision(v.pos.x, v.pos.y, 10, 10, player.x, player.y, 10, 10) then player.health = player.health - 5 end end [/code]
[QUOTE=Bambo.;30135497]This is the best I can do really[/QUOTE] May I suggest you create a box/rectangle class, and that you just pass that into the heck collisions instead of the x, y, height & width of each box
[QUOTE=Richy19;30135518]May I suggest you create a box/rectangle class, and that you just pass that into the heck collisions instead of the x, y, height & width of each box[/QUOTE] Ah thanks, but is this the only way i can do it? it seems kinda bad.
[QUOTE=Bambo.;30135821]Ah thanks, but is this the only way i can do it? it seems kinda bad.[/QUOTE] As I believe you completely ignored my post, here is the link again: [url]http://www.metanetsoftware.com/technique/tutorialA.html[/url] It's fairly easy to implement.
[QUOTE=DrLuke;30136528]As I believe you completely ignored my post, here ist the link again: [url]http://www.metanetsoftware.com/technique/tutorialA.html[/url] It's fairly easy to implement.[/QUOTE] Ah im sorry, thanks alot! I'll start on it now.
Sorry, you need to Log In to post a reply to this thread.