Lasers with box2d
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- slime
- Solid Snayke
- Posts: 3160
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Lasers with box2d
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.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Lasers with box2d
Well, /technically/ a laser wouldn't have any effect on an object's velocity.
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.
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+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- slime
- Solid Snayke
- Posts: 3160
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Lasers with box2d
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).
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Lasers with box2d
Things like spacial hashes and quadtrees might help.
Help us help you: attach a .love.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Lasers with box2d
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.
You can detect collisions with them, and at the same time they "go through" everything.
When I write def I mean function.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 2 guests