Game Development Community

How to grab my gun?

by Martin Askestad · in Artist Corner · 01/06/2005 (1:15 pm) · 13 replies

I've build a neat looking gun in Milkshape. I'm now going to atemp to export it to Torque. However. I'm unsure how I should do so my character can grab the gun. Also how do I make sure that the character grabs it by the handle??

Regards
.M

#1
01/06/2005 (1:59 pm)
I haven't bought torque yet (planning on buying it soon), so I am not positive, but don't you mount the gun on a node on your character? In the Torque demo, it has a brief part on mounting (showing the capabilities). Mounting should be in the documentation, so you may want to look into it. Also, I recommend 3D Game Programming All-in-one. It will help you greatly with these problems. In the book he uses Torque and Milkshape too. Good Luck!
#2
01/06/2005 (2:34 pm)
Go into the torque folder. Then into starter.fps/server/scripts, and open crossbow.cs. Search for crossbow.dts, and replace it with the name of your exported dts. (Be sure to copy your gun.dts file to the same place crossbow.dts is, along with any textures). If you want to make a new weapon, study crossbow.cs and see how they make it. You can even copy the same code and tweak until you get the desired effect. Actually coding is going to help you a ton more than asking about how to do every little thing, believe me. I didn't really start understanding how to work with torque until I started integrating resources and replacing things like the sky textures, weapons, creating new items to pick up... just tinker around with little things and it gets clearer and clearer.
#3
01/06/2005 (4:28 pm)
Don't I have to add something to the model so that the character can hold on to it??

I've managed to get the gun in the game. Rotating neatly on the ground. But the guy won't pick ut up when I walk over it.
#4
01/06/2005 (4:42 pm)
Martin, you have to add a node (a joint i believe, in milkshape) to the handle called MountPoint. "MuzzlePoint" is a node you place at the end of the barrel which tells the engine that thats where rounds fire from. "EjectPoint" is where casings/shells will shot from.

As for how to get him to pick it up, you need to add it to his inventory in player.cs. Just scroll down and find where it defines how many of each weapon and rounds he can carry and add the name that you gave your weapon in it's cs file.

Then in the config.cs (located in starter.fps/client) you have to bind your weapon to a key.

Hope this helps. :)
#5
01/06/2005 (5:52 pm)
Cool it works!
Strangley enough the gun floats in space in front of the character. Probably because the gun has'nt been tweaked.
#6
01/06/2005 (6:48 pm)
A floating weapon could be a couple of things.

First, it could be the mount nodes. If your gun mount node is directly on the handle and you are using the orc (or a different stock Torque character), then its probably NOT the mount nodes. If you are using your own character, make sure "mount0" is placed neatly on a hand (or whatever should be holding the weapon).

It could also be the offsets. In the cs file for the weapon, there is a section that lets you offset how the weapon placed in the first-person view. Find the section and mess with the values a little bit to see what happens.
#7
01/06/2005 (7:31 pm)
After a bit of fondeling the the model in milkshape, I've managed to get a pretty convincing grip on it.

I moved the MountPoint to 0 0 0 in milkshape and aligned the gun there after. And then I rotated in 180 degrees. And voila! the orc is now holding a Cold 1911 gun. Not the most original weapon, but quite unusual for orcs.

Now comed the exciting part with the animation etc. :-)

Thanks for the help!.
#8
01/09/2005 (2:03 pm)
I'm looking for where weapons get connected with players.

I don't see it.

Can someone, for example, point out where this is done in starter.fps? I've tried a plain text search for "crossbow" and all I find is the declaration of the weapon.

I'm trying to go to the next step and create other weapons that the player can switch through.
#9
01/09/2005 (2:27 pm)
I'm watching carefully for the reply to @Edward, and I'm going to piggyback my questions onto his.

What I've found so far is this:

In server/scripts/game.cs is the TS command
%player.mountImage(CrossbowImage,0);
.

CrossbowImage
is defined in server/scripts/crossbow.cs by the following code scraps:
datablock ItemData(Crossbow)
{
  ...
  shapefile="/data/yadda/yadda.dts"
  ...
  image = CrossbowImage
};

datablock ShapeBaseImageData(CrossbowImage)
{
   shapefile="/data/yadda/yadda.dts";
   mountPoint = 0;
};


What I've figured out is that the player object uses the method
mountImage
to mount the crossbow, with the crossbow's
mountPoint
on the player's
mount0
.

At this point I get lost. I can't figure out how to mount other objects - like skis and ski poles.

Take, for example, putting skis on %player's feet. It looks like
mountImage
only takes integers for mount points, converting 0 to mount0, for example. But I noticed in a doc somewhere that characters can optionally include two mount points called Ski0 and SKi1. How do I use these mount points? (Or should I just call them
mount2
and
mount3
?
#10
01/09/2005 (3:20 pm)
My search for "crossbow" had case sensitivity turned on.

I'm so embarassed.
#11
01/10/2005 (3:19 pm)
Heh - that's funny. We've all done it, too.

Okay, I got mounting figured out.
Forget Ski0 and Ski1. mount0 goes in rhand, mount1 in lhand, mount2 in rfoot and mount3 in lfoot.

When you create your shapebase in ski.cs (which you copied from crossbow.cs -- how else?), make sure you specify mountPoint = 2; or 3. (I had to create 2 separate shapebases in ski.cs, one for each ski. Can't use the same shapebase twice. So I have LSki and RSki, LPole and RPole.)

Then you need to make sure that .... um .... either player.cs or game.cs in /server/scripts does an exec on your new .cs files to load them. For some reason, %player.mountImage executes without complaint, whether the item to mount exists or not.

Finally, you add %player.mountImage(, ); (like %player.mountImage(SkiImage, 2); to game.cs if it belongs on the player at the start of the game, or player.cs / aiPlayer.cs / wherever.cs if it gets added later.

There's a file somewhere called dtsScene.cfg that has a list of mountPoints. I added mount2 and mount3 to the list, but I did it out of superstition, not knowing if it really made a difference.
#12
01/10/2005 (3:59 pm)
All,

I was just about done answering thread when I saw this, and thought I'd post to just one more. EGTGE Volume II will cover weapons, but to (hopefully) assist here I'll give a summary of 'one' way to make weapons work:

To make a weapon requires (minimal list):
- Item representation of weapon (weapon as item)
- Image rrepresenations of weapon (weapons as shapeBaseImageData) can use same mesh as above.
- State machine declaration in shapeBaseImageData
- Accompanying scripts (see below)
- Projectile datablock
- Player with appropriate mountpoint.
- Weapon mesh with appropriate mountpoint and muzzlepoint.

Your weapon should have these nodes:
www.hallofworlds.com/pages/Torque/TorqueImages/WeaponHelp.jpg
Your Player should have a node named: mount0 (usually in right hand as Ray points out)

Once you have the meshes and the datablocks defined, you can set up your scripts.

The series of events is:

- Player Collides with item representation (Fires playerData::onCollision() [named armor::onCollision] in TGE kit)
- This calls ShapeBase::pickup()
- This calls Weapon::onPickup()
- This calls ShapeBase::use()
- This calls weapon::onUse() - Here, finally.... we mount the image representation to the players mount0 node (joint).

Somewhere along the way, the item representation is removed from the world (I forget when, but as you read throught the TGE scripts, you'll see a call to delete at some point).

For the best example of how this works, take a look at crossbow.cs.

To simplify your life, it is usually nice to put information in the datablocks that can then be used by your scripts. For example, the item representation has a reference to the image that is used to represent it:
datablock ItemData(V12RifleMark0) {
    category    = "V12Rifles";
    className   = "Weapon"; 
    shapeFile   = "~/data/Shapes/Weapons/V12Rifles/v12mark0.dts";
    mass        = 100;
    elasticity  = 0.2;
    friction    = 0.6;
    image       = V12Mark0Image;	
};

Likewise, because you may drop the weapon later, the image datablock has a refernce to the item datablock:
datablock ShapeBaseImageData(V12Mark0Image) {
    className	   = "WeaponImage"; 
    shapeFile           = "~/data/Shapes/Weapons/V12Rifles/v12mark0.dts";
    mountPoint          = 0; 
    eyeOffset           = "0.1 0.2 -0.55"; 
    correctMuzzleVector = false; 
    casing              = RifleShell; 
    item                = V12RifleMark0;
    projectile          = RifleProjectile;

// to be continued...

Note that the image datablock specifies the mount point this image mounts to: mountPoint = 0; This is required and must match the player's mount point name. Actually almost all mount points are named mountN, where N == 0..31]. There are aliases and special mounts, but I digress...

Statemachines can be notoriously difficult to make, so if you need a simple one, this definition will create a weapon that does not need ammo:
// ... continued from above

    stateName[0]                                  = "Preactivate";
    stateTransitionOnLoaded[0]           = "Ready";

    stateName[1]                                  = "Ready";
    stateTransitionOnTriggerDown[1]   = "Fire";

    stateName[2]                        = "Fire";
    stateTimeoutValue[2]            = 0.1;
    stateTransitionOnTimeout[2] = "Ready";
    stateFire[2]                            = true;
    stateAllowImageChange[2]   = false;
    stateScript[2]                         = "onFire";
    stateEmitter[2]                      = RifleFireEmitter; 
    stateEmitterTime[2]               = 0.3;
};
#13
01/10/2005 (3:59 pm)
Post continued:

There is much more to tell, but I think that with the info in this thread (from everyone) you should be good to go on figuring this out.

Again, EGTGE Volume II will cover weapons. It will provide a step by step creation of three rifles, two grenades, two land mines, and various other weapons. The finished versions of these weapons will also be included in the code kit.

An official announce of EGTGE Volume I and II is yet to occur, but you can see some screens from the 'EGTGE Volume I Code Kit' here.


[HOW]EdM|EGTGE

PS - I'm not going to correct my typos...please forgive... :)