Game Development Community

Mounting an sgLightObject to a DTS

by Jake H. · in Torque Game Engine Advanced · 04/02/2009 (11:46 am) · 3 replies

I am working on a project in which a fire alarm is going to be crucial. Of course, in the case of a fire alarm, you have sound radiating from it (easy to script, attaching it to the object) and a light on the top to see through the smoke. Is there some way to attach an sgLightObject to a point on a DTS? I'm aware this will probably involve some scripting, but all I can find is the attachToObject command, which involves fxLights, best I can tell. Also, some documentation states that his command only links the object and the light so if the light is deleted, so is the object and vice versa.

ANY help would be greatly appreciated.

#1
04/02/2009 (12:22 pm)
Take a look at the sgExamples.cs file, it shows an example of attaching a light to a swinging spot light. In player.cs function Armor::onAdd() ,the commented code, there is an example of attaching a light to the player object -- the same principle works for headlights on a vehicle also. Armor::onRemove deletes the light when the player is killed/drops/removed.

I never messed around with the "mount light" though, but it should give you something to "play with". Should be a simple test to find out what happens if one is deleted...
#2
04/03/2009 (7:17 am)
Done. Worked like a charm! Thank you, I don't know why I didn't think to look there to begin with.

On a slightly different note, I tried the deletion thing, and the light stays in if you delete the object! Not the other way around though...
#3
04/03/2009 (1:27 pm)
Cool, glad you got it. To also delete the light when deleting the object, try adding an "::onRemove" function for the object to handle the light removal for you.
function someObject::onRemove(%this, %obj)
{
   if (isObject(%obj.light))
      %obj.light.delete();
}
Make sure you add %obj.light = %light to the someObject::onAdd() function, or wherever you attach the light, for that to work.