dennis Posted January 7, 2015 Share Posted January 7, 2015 Hi guys, I wanted to draw a light from my object which is a box Problem is it won't work. I placed the following inside script:start light = Pointlight:Create() light:SetPosition(0,0,0) light:SetRange(5) light:SetParent(self.model) What am i doing wrong? Cheers Quote Link to comment Share on other sites More sharing options...
Rick Posted January 7, 2015 Share Posted January 7, 2015 Do you get an error? What is self.model? If you want that to refer to the entity the script is attached to it's self.entity. Quote Link to comment Share on other sites More sharing options...
dennis Posted January 7, 2015 Author Share Posted January 7, 2015 Self.model is the box the script is attached to. When I change it to self.entity it will work but the box isn't casting light. It just flickers. But no errors Quote Link to comment Share on other sites More sharing options...
Rick Posted January 7, 2015 Share Posted January 7, 2015 Self.model is the box the script is attached to. What is your thinking here? If you have a script attached to a model the way your refer to that model from inside the script is self.entity. This assumes LE 3.x. The reason you saw nothing before was because self.model doesn't refer to anything so it's nil and you were setting the parent of the light to nothing/nil which means your light would have been at the center of your scene since you set it's position to 0,0,0. Is this a csg box? If so then it's position value is the center of the box. So your light would be inside the box shining outward but might look funky since it's inside the box. You'd want to offset it a little. For testing hardcode the offset, but you can get the bounding box of the csg box and split the width in 1/2 to be more accurate but for now I'd leave that for another day and just manually move it forward with Move() after you set it's parent. Quote Link to comment Share on other sites More sharing options...
dennis Posted January 7, 2015 Author Share Posted January 7, 2015 Still the samen problem. when I change the SetPosition to: 0,1,0 it gets : When I change it to 0, -1, 0 to appear benead my model... it gets black. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 7, 2015 Share Posted January 7, 2015 What are you expecting? "I wanted to draw a light from my object which is a box" isn't detailed enough. Are you expecting the light to shine down from the box bottom of the box? Up from the box? What is your final result you are aiming for. Quote Link to comment Share on other sites More sharing options...
dennis Posted January 7, 2015 Author Share Posted January 7, 2015 I wanted to draw the light under the box. Like a ceiling light. And a ceiling light is what I am aiming for. Sorry for not explaining good enough. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 7, 2015 Share Posted January 7, 2015 Give this a shot self.light = Pointlight:Create() self.light:SetPosition(self.entity:GetPosition()) self.light:Move(0, -1, 0) -- may have to play with the -1 value self.light:SetRange(5) I can't recall if lights start pointing downward but if not you'd have to rotate it too. Unless you plan on moving the box during runtime you don't need to make it the parent. Just curious though, why do this in code? Why not just make a point light in the editor and line it up in the editor and make it a child of the box? Then you can make a prefab of it. Quote Link to comment Share on other sites More sharing options...
dennis Posted January 7, 2015 Author Share Posted January 7, 2015 You are my hero, it works now ! thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.