Game Development Community

Attatch a light to a weapon

by Tim Heldna · in · 01/19/2006 (9:52 pm) · 15 replies

@ John Kabus

Just got the 1.4 lighting kit edition of Torque & it's great. Having lots of fun discovering & using all the cool new stuff you've added in, very good work indeed.

One question though, i noticed you can attach a light to a static shape. Is there anyway of doing this for a weapon image? The reason i ask is i need a laser sight & a torch on a couple of my weapons. Any ideas or suggestions would be greatly appreciated.

#1
01/20/2006 (12:02 pm)
Hi Tim,

You need to have an object to mount the light to (any GameBase derived objects will work). An image only exists as a datablock, the mounting object (the object the image is mounted to) handles all of the mounting, rendering, and animation.

But you can still achieve the effect you are going for. For any image you want to attach a light to override the "onMount" and "onUnmount" events in script. In those add code to create a light and attach it to the mounting object, and then detach and delete the light respectively.

This will make the light attachment image (weapon) specific just like you're going for.

Hope this helps!

-John
#2
01/21/2006 (12:03 am)
Thanks John,

I did what you suggested & that's exactly what i wanted. Worked like a charm, thanks for the quick response.
#3
02/22/2006 (10:20 pm)
Hai
I'm working in Synopse Gaming
I need a help
I've added a light to the world
when i change the enable property of the light at runtime its not working
but works only when i relights it in the world editor
#4
02/23/2006 (10:57 am)
Hi Vinoth,

Are you trying to change the light object or the datablock? If you are changing the object try using this instead:

<lightname>.setEnable(true);

This code sets the value and tells Torque's networking layer to update the clients (unlike setting the value directly).

-John
#5
04/05/2006 (6:25 am)
@John K

I'm trying to add a light to the crossbow and am having difficulty getting it to mount to the weapon. Instead, the only thing that I have been able to attach it to is the player itself. How would I attach the light to the muzzlePoint of the Crossbow instead?

thanks, John T

function CrossbowImage::onMount(%this,%obj,%slot)
{
// Images assume a false ammo state on load. We need to
// set the state according to the current inventory.
if (%obj.getInventory(%this.ammo))
%obj.setImageAmmo(%slot,true);

%light = new volumeLight() {
dataBlock = "sgMountLight";
rotation = "-0.357694 0.933839 9.9834e-009 180";
scale = "1 1 1";
dataBlock = "sgMountLight";
Enable = "1";
IconSize = "1";
ParticleColorAttenuation = "1";
Texture = "common/lighting/lightFalloffMono.png";
lpDistance = "0.35";
ShootDistance = "5";
Xextent = "0.6";
Yextent = "0.6";
SubdivideU = "4";
SubdivideV = "4";
FootColour = "1.000000 1.000000 1.000000 0.182000";
TailColour = "0.000000 0.000000 0.000000 0.000000";
};
%light.attachtoobject(%obj);
}
#6
04/07/2006 (11:54 am)
Hi John,

In Torque the mounted weapons are ShapeBaseImageData datablocks, not actual objects, so they don't support mounting or attaching. You can mount ShapeBase derived objects to other objects, and these would allow lights to be attached, however that has higher overhead than using an image datablock.

-John
#7
04/21/2006 (8:34 am)
Thanks John for the above information.

It took me a while to finally realize that an ItemData object will not render when mounted to a node. I have switched over to using a StaticShapeData and I am now getting my flashlight mounted properly and a light coming out at the proper node as well.

One question I do have is, I am getting some odd artifact from the sgMountLight. It shows as an outline of a texture map right at the starting point of the beam, I believe it is related to using the Flares. I have tried turning FlareTP to false but I am still getting this outline and even if I remove the Flare name, it appears to substitute the lightFalloffMono.png in its place. Also, FlareOn is already set to false.

Do you have any idea how to either turn off this flare or else to keep from the outline showing? Hope you can understand what I'm explaining.

John
#8
04/21/2006 (4:01 pm)
Hi John,

There is a quad rendered at the bottom of the volume light - you can comment out the code for it in "volLight::renderGL" in the file "game/fx/volLight.cc" (the section of code is labeled with the comment "Draw the bottom foot... this is basically the glowing region.").

-John
#9
04/22/2006 (4:25 pm)
Sorry to be a pest about this, but I really need this to work.

I have abandoned my earlier attempt of creating a StaticShapeData object and attaching the light to it. Instead I am using your first suggestion about mounting it to the player and positioning the light so it appears to be coming from the weapon (at least I thought that is what you were implying).

It looks like this will work until I tested it networked and the players vanish that have a light mounted yet they are in the game world and I can collide with them on the client. The server side everything looks perfect.

Am I doing something really stupid here?

John
#10
04/24/2006 (10:50 am)
Hi John,

Does this happen with a clean TLK 1.4? Also make sure the volume light is not too large and obscuring the player (this shouldn't happen, but just in case).

-John
#11
04/24/2006 (11:39 am)
Yes, I just verified it now.

StongholdNight.mis
I used a clean TLK 1.4 and only added the Crossbow::OnMount code I posted back a few post above to the Crossbow script. I then start the game on one machine as the server and the light displays fine. I then go stand in front of the fire pit by the lake and wait for a client to connect.

On a second machine I go ahead and join the game. Everything looks fine, the light is displaying in his hand (unfortunately facing the wrong way but I can always fix that later). I then run over to the fire pit and the player from the server side is not visible nor is the name tag. Yet, when I walk around the fire pit I bump into the player.

StrongholdLightpackDemo.mis
Did the same procedure as above but for some reason the player shows up in this mission (MINUS THE LIGHT). The light for the client player displays normally but not the servers player light.

Thanks again for taking the time to look into this!
John
#12
04/24/2006 (11:58 am)
We'll need to move this into the TLK private forums. There are a number of things we can test out to see whats happening.
#13
04/24/2006 (12:00 pm)
Should I create a new thread or will you move this one over?
#14
04/24/2006 (4:03 pm)
I dont think this forum software supports moving threads, so go ahead and create a new one.
#15
05/25/2006 (4:10 am)
Thanks john