libgdx / box2dlights

Fork of box2dlights by Kalle Hamalainen
Apache License 2.0
256 stars 81 forks source link

Bodies with multiple fixtures block light rays from lights attached to the body. #36

Closed seannybgoode closed 9 years ago

seannybgoode commented 9 years ago

Found the issue in libGDX 1.4.1 running box2dLights. Using RUBE to get multiple fixtured bodies on the go for some advanced collision detection, but when I attach a light to the body, the fixtures block the light rays. I can work around, but thought I should let you guys know.

rinold commented 9 years ago

Hi, @seannybgoode, Afaik, you can use the Light.setContactFilter(...) method to ignore specified fixtures when ray casting. Could it solve the problem in your case?

seannybgoode commented 9 years ago

Can you elaborate on how that would work without breaking collisions?

rinold commented 9 years ago

Just tried on box2dlights test app, and for example I had the:

Light.filter: categoryBits = 0x0001;

world box with filter: categoryBits = 0x0002; maskBits = 0x0001 | 0x0004;

light balls bodies: categoryBits = 0x0004; maskBits = 0x0002 | 0x0004;

And in that case the balls were colliding with other balls and world box (screen limiting rectangle), but the lights were ignoring the balls and produced no shadows, while the world box was not ignored by lights.

Or you can use the negative group index, e.g.: Light.filter: groupIndex = -1;

Your body fixtures: groupIndex = -1;

In that case the lights will ignore fixtures, but the fixtures will not collide with themselves (and other fixtures with groupIndex -1) but will collide with all other fixtures.

I know, sometimes from the first look it might be quite complicated to use the filtering in box2d, so, what I see, possibly we could add something like ignoreAttachedBody(boolean flag) method with param, that will specify if the attached body fixtures should be ignored.

seannybgoode commented 9 years ago

I'd love to see an easy to use method added for sure. I'll give this mask system a shot though. You're not wrong about it being complicated, that's for sure.

Question: why is Light.filter static? I don't want all lights to have the same contact filter. Some lights should collide with the player, and some lights should avoid the fixtures mentioned in the bug report.

rinold commented 9 years ago

Question: why is Light.filter static? I've also already had the same question in my head while was looking at your issue. I'm not the author and currently just supporting box2dlights as I can, so can't say if we ever will know why it's so, think it's historical.

I'll think about splitting the filter to both static (global to all lights) and local light filter. Also will try to add method I've wrote above in next version.

rinold commented 9 years ago

Hi @seannybgoode,

I've added the Light.setIgnoreAttachedBody(...) method, could you please check if this will solve your request?

The new development box2lights version is ready and you could download it from here - the 1.4-SNAPSHOT version is what you will need.

rinold commented 9 years ago

Hi @seannybgoode, have you checked it yet? I'm going to close this issue.

seannybgoode commented 9 years ago

Hi, sorry we haven't had a chance to check. We ended up using Filters to have the light not collide with the fixtures.

On Fri, Jan 30, 2015 at 12:40 AM, Mikhail notifications@github.com wrote:

Closed #36 https://github.com/libgdx/box2dlights/issues/36.

— Reply to this email directly or view it on GitHub https://github.com/libgdx/box2dlights/issues/36#event-227389195.