Game Development Community

Weapons - Gun problem

by Gleznov · in Artist Corner · 07/17/2005 (2:41 pm) · 8 replies

Hi,

I created a gun I'd like to test in my game. I'm having a few problems though. I have the gun with the three joints, mountPoint, muzzlePoint and ejectPoint. Here's what's happening:

1) If I export my model (DTS Plus from Milkshape) as is, only the handle of the gun shows up if I run some code that drops it at my position in the game.

2) If I regroup all the parts of the model into one part, then export, I get the full model, but only one texture over the whole thing. I'm not using a skin, just a few different textures in Milkshape on each part. Maybe this won't work? But regardless, do you have to have your weapon/item be only ONE group? That makes future editing incredibly difficult.

3) I copied another weapon's .CS file, changed everything to match my new weapon (DTS file, WAV files, etc) and still if I run into it (either the handle from part 1 or the one-textured model from part two) I just bump it away from me in the game world. Maybe my problem is the way I'm creating the object in the game world - I have a script I'm executing from the console as follows:

datablock ItemData(TestShape)
// ----------------------------------------------------
// Definition of the shape object
// ----------------------------------------------------
{
// Basic Item properties
category = "Weapon";
className = "Weapon";
shapeFile = "~/data/models/weapons/laserpistol.dts";
mass = 1; //we give the shape mass and
elasticity = 0.2;
friction = 1; // friction to stop the item from sliding
// down hills
emap = true;
pickUpName = "A LaserPistol";
image = LaserPistolImage;
};

function InsertTestShape()
// ----------------------------------------------------
// Instantiates the test shape, then inserts it
// into the game world roughly in front of the
// the player's default spawn location.
// ----------------------------------------------------
{
// An example function which creates a new TestShape object
%shape = new Item() {
datablock = TestShape;
rotation = "0 0 1 2.07104"; // initialize the values
// to something meaningful
};
MissionCleanup.add(%shape);

// Player setup
%shape.setTransform("0.0566379 -1.05615 200.016 0 0 1 2.07104");
echo("Inserting Shape " @ %shape);
return %shape;
}

This is set up to drop the weapon model right at my starting location.

Glez

#1
07/17/2005 (4:03 pm)
I cant be sure what the problem is because i cant see all the scripts you're using, but to use the script weapon system you need to do a few more things.

you need to modify the player datablock to pick up the weapon. add a field to the player datablock called:

maxinv[name]=50; where name is the name of the datablock you want to pick up. you should also add a field to the player shapebase object called inv[name]=0;.

you also need to create a new shapebaseimagedata called laserpistolimage. creating a new shapebaseimagedata is rather involved because you have to code the state behavior. for the time being, you may want to just use an existing image and just change the dts file inside.

good luck
#2
07/17/2005 (5:00 pm)
I already have that in my LaserPistol.cs file - all the state info, etc. As well as the ammo/projectile datablocks which are renamed for LaserPistol but point to the crossbow stuff (for now). I've also revamped my model and skinned it, and regrouped the whole thing into one group (guess if it's finished, I don't need to animate anything on it so it won't matter). It shows up correctly in the game now. But still when I touch it, instead of picking it up it bounces back a few feet. Any other ideas? In that code I gave above, am I instantiating it as a weapon or as some bizarre item that looks like my weapon?

Also, in player.cs I already have the:
maxInv[LaserPistol] = 1;
maxInv[LaserPistolAmmo] = 20;

I don't see anywhere a plain:

inv[Crossbow]

so I don't know where I should plug one for LaserPistol? If it helps, here's my player.cs code (on a link):

http://rafb.net/paste/results/k33EbV60.html

and the one for my weapon:

http://rafb.net/paste/results/QPRJIw36.html

Glez
#3
07/17/2005 (5:45 pm)
The only thing i that i can see is that the name you give for the itemdata datablock has to be the same name you put for the maxinv field. instead of TestShape, try renaming the datablock laserpistol. other than that, everything else looks fine.
#4
07/17/2005 (6:52 pm)
Well that definately helped some - now I apparently pick up the weapon - it doesn't get knocked around. However, if I spawn another one, it gets knocked around (why don't I just run through it like the other weapon in this game if I already have it?) and I don't seem to be holding it. The crossbow works fine, I hold it in my hand and it shoots and all. But when I pick mine up, it disappears, although I see things in the console about weapon acquired. Let me just make sure I'm correct on the joints in the weapon:

mountPoint = the name of the joint that attaches to my char's hand
ejectPoint = the name of the joint where shells would be expelled
muzzlePoint = the name of the joint where the bullets come out

Right? I'm working from the 3d Game Programming All In One book, so could some of these joint names have changed since the writing?

Glez
#5
07/17/2005 (8:07 pm)
Those nodes are correct. i dont know what the problem may be. the only possible source of the problem i can see is exporting the model in the wrong orientation so its sticking through the character when its mounted. sorry i dunno what the problem may be.
#6
07/17/2005 (8:10 pm)
DTS Plus you say?

Check the names of your shapes. By default, Milkshape increments numbers at the ends of shapes (Cyclinder01, Cyclinder02, etc). DTS Plus reads these numbers as different LODs. Remove any numbering (not specified by the DTS Plus docs) trailing your shape names and see if your model doesn't magically appear. ;)
#7
07/17/2005 (9:03 pm)
Well, the regroup had named itself Regroup3, and I changed it to LaserPistol and I also had 3 lingering materials, LP1, LP2 and LP3 which I deleted. I then reexported. But same thing - it shows up when I run the script to drop it in the game, but if I run over it, it disappears.

Glez
#8
08/02/2005 (7:48 pm)
Aha!!!

OnServerCreated in server.cs was missing:

Exec("./weapons/laserpistol.cs");

:) :) :)

Glez