Lasers with box2d

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
slime
Solid Snayke
Posts: 3160
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Lasers with box2d

Post by slime »

What is a good, clean way to have laser-type (instantaneous beam which will go in a straight line to its max distance or to any object it hits, with a long lifetime) objects using the box2d API? Stuff I've tried has been very hack-ish and doesn't work quite right.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Lasers with box2d

Post by Taehl »

Well, /technically/ a laser wouldn't have any effect on an object's velocity. :P

But to achieve what you want to do, I guess you would need to make a function that checks if any bodies intersect with a given line, then impart velocity appropriately.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
slime
Solid Snayke
Posts: 3160
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Lasers with box2d

Post by slime »

Right, I'm not too worried about the collision response, I just want something that works well with box2d and won't cause performance problems (line detection might have slowdowns because as far as I'm aware I would be checking against every damageable object in the game, which could be a lot).
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lasers with box2d

Post by Robin »

Things like spacial hashes and quadtrees might help.
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Lasers with box2d

Post by kikito »

What about a 3-pixel-width rectangular sensor shape (or several of them aligned)?

You can detect collisions with them, and at the same time they "go through" everything.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 3 guests