Jump to content

drawing a light from object


dennis
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...