matiasah / shadows

Shädows - A Shadows & Lights engine for löve
MIT License
169 stars 9 forks source link

Attatch lights to bodies #10

Closed Skeletonxf closed 7 years ago

Skeletonxf commented 7 years ago

Would it be possible to attach lights to bodies, specifically the love2d physics bodies this library can sync up with so that the light gets automatically destroyed when the body does and the light just follows the body around till then?

matiasah commented 7 years ago

Edit: I'd prefer to have a 'BodyTransform' class which would be for bodies, I'll see how to implement it.

matiasah commented 7 years ago

Does this suit your needs? https://github.com/matiasah/shadows/wiki/BodyTransform

You can attach lights & stuff to that transform by using the transform of the stuff you want to attach.

Just use whatLight:GetTransform():SetParent( LightWorld:TrackBody( whatBody ) )

Skeletonxf commented 7 years ago

This page https://github.com/matiasah/shadows/wiki/Light has become out of date with the additions :P Yes this works very well for what I need, however I had to add a line to BodyTransform.lua at line 6

BodyTransform.__index = BodyTransform

as the metatable method wasn't getting looked at by lua and initially I was getting

Error: shadows/BodyTransform.lua:22: attempt to call method 'SetLocalRotation' (a nil value)
matiasah commented 7 years ago

Whoops, looks like I missed it. Just added it, so we're fine?

Skeletonxf commented 7 years ago

Should be now.