Game Development Community

Weapon effects

by Matt Sanders · in Torque Game Engine · 11/12/2004 (8:39 am) · 14 replies

I was just wondering where would be a great place to look for documentation on how to make custom weapons. I have already modeled, skinned, mounted my weapon in game but I still have the crossbow bolts come out of it. I am trying to control how fast the weapon shoots multiple projectiles (like a machine gun). Everything that I have found so far talks about a rocket launcher and has no info on speeding up the consecutive launchings of the rocket. I also have read the book 3d Game Programming all in one, and in one of the chapters it says that it will talk more about adding functionality to custom weapons but then has no more info (like it was intentionally left out or something). Any help is more then appreciated. I am sure It cannot be too hard but I have just not been able to find any information on the subject... Thanks in advance

#1
11/12/2004 (9:34 am)
Try weapon tutorial:
http://www.codesampler.com/torque.htm
#2
11/12/2004 (12:31 pm)
I knew that I would get directed to that some how. :) I checked that one and doesn't help me out with what I am trying to do. the weapon is a rocket launcher and is very similar to how the crossbow works. ty for your response but I need something that might have a little more info on how to speed up or slow down the fire method. I want to make a machine gun and some other weapons with similar characteristics.
#3
11/12/2004 (12:48 pm)
Ok... I figured this out all by meselfis quite awhile back so here are what you will need to search for in crossbow.cs is...

muzzleVelocity "you can change this speed much higher. It's default is 100 I think."
-
velInheritFactor "this is set to 0.3 as a default it is the gravity for the projectile if oyu set it to about 0.001 you should get the aout the right gravity for a bullet."
-
stateTimeoutValue[3] "this is the transition inbetween shots. It is set to 0.2 you can set it to the desired amount I would guess 0.0004 to test it out."
-
"And to change the projectile you can search for projectile.dts that is the arrow file. You can change that to a new file if you like."


Well that should get you started for now I'll be happy to answer any questions ya have.

Max
#4
11/12/2004 (2:05 pm)
Thanks for the tip. this helps me out a alot. the bullets act alot more like bullets. I still however cannot get it to shoot as fast as a machine gun would even when I put StateTimeoutValue[3] to 0.0. is there anything else that may need to be changed or is there someone who knows how to make a machinegun. TY for the help.
#5
11/12/2004 (2:24 pm)
If you post the "datablock ShapeBaseImageData(CrossbowImage)" datablock I'll take a lookie at it and tell ya what to do from there.
#6
11/12/2004 (2:27 pm)
Datablock ShapeBaseImageData(machinegunImage)
{
// Basic Item properties
shapeFile = "~/data/shapes/machinegun/machinegun.dts";
emap = true;

// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 0;
eyeOffset = "0.4 0.5 -0.5";

// When firing from a point offset from the eye, muzzle correction
// will adjust the muzzle vector to point to the eye LOS point.
// Since this weapon doesn't actually fire from the muzzle point,
// we need to turn this off.
correctMuzzleVector = true;

// Add the WeaponImage namespace as a parent, WeaponImage namespace
// provides some hooks into the inventory system.
className = "WeaponImage";

// Projectile && Ammo.
item = machinegun;
ammo = machinegunAmmo;
projectile = machinegunProjectile;
projectileType = Projectile;

// Images have a state system which controls how the animations
// are run, which sounds are played, script callbacks, etc. This
// state system is downloaded to the client so that clients can
// predict state changes and animate accordingly. The following
// system supports basic ready->fire->reload transitions as
// well as a no-ammo->dryfire idle state.

// Initial start up state
stateName[0] = "Preactivate";
stateTransitionOnLoaded[0] = "Activate";
stateTransitionOnNoAmmo[0] = "NoAmmo";

// Activating the gun. Called when the weapon is first
// mounted and there is ammo.
stateName[1] = "Activate";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.6;
stateSequence[1] = "Activate";

// Ready to fire, just waiting for the trigger
stateName[2] = "Ready";
stateTransitionOnNoAmmo[2] = "NoAmmo";
stateTransitionOnTriggerDown[2] = "Fire";

// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Reload";
stateTimeoutValue[3] = 0.0004;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateSound[3] = machinegunFireSound;

// Play the relead animation, and transition into
stateName[4] = "Reload";
stateTransitionOnNoAmmo[4] = "NoAmmo";
stateTransitionOnTimeout[4] = "Ready";
stateTimeoutValue[4] = 0.8;
stateAllowImageChange[4] = false;
stateSequence[4] = "Reload";
stateEjectShell[4] = true;
stateSound[4] = machinegunReloadSound;

// No ammo in the weapon, just idle until something
// shows up. Play the dry fire sound if the trigger is
// pulled.
stateName[5] = "NoAmmo";
stateTransitionOnAmmo[5] = "Reload";
stateSequence[5] = "NoAmmo";
stateTransitionOnTriggerDown[5] = "DryFire";

// No ammo dry fire
stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";
stateSound[6] = machinegunFireEmptySound;
};
#7
11/12/2004 (2:28 pm)
I think I have a general Idea of what I need to do. just need to understand the state stuff a little more. I noticed that with the crossbow the state goes to reload every time you fire. that is what is causing the delay... The main thing I will need to do is make it so you have a clip of like 50 bullets and your gun can hold up to like say 5 clips... so you will not have to reload until you hit 50
unless you just want to reload the clip when you have spare time.
Is there some documentation on the state stuff... :)
#8
11/12/2004 (2:50 pm)
With a bit more tweaking I found out the the StateTransitionOnTriggerup[3] comes in handy this is what I did to make it work

// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Fire";
stateTimeoutValue[3] = 0.0004;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateSound[3] = machinegunFireSound;
stateTransitionOnTriggerup[3] = "Ready";


I would still like to hear more from you Max on how you would do it...
#9
11/12/2004 (5:35 pm)
Hmm thats odd. I just have

// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Reload";
stateTimeoutValue[3] = 0.00002;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateSound[3] = CrossbowFireSound;


If have any other Q's just ask. If you like I can send you a vid of one or the simple script I have at the moment.

Max
#10
11/12/2004 (6:59 pm)
Anything is helpful. I tried to make the script like you had it but it would pause after every shot to do the reload. I also am now having a problem with it freezing my computer when I shoot the water. I am going to make a whole new machinegun.cs file from scratch so I will definitely need to look into all of projectile stuff. What I would like is to be able to see a trail where the bullet was so it looks like something is coming out of the gun really fast. thanx max and if you have any more info that may help me out I would really appreciate it.
#11
11/12/2004 (7:23 pm)
Matt can you post your E-mail adress so I can send you a file?

Max
#12
11/13/2004 (5:48 am)
I put my email under my profile so you can just click on my name and get my email address.
#13
11/13/2004 (3:58 pm)
The weaponpack helped me a lot you can find that in the code snipets. I believe that the machinegun script used is from that.
#14
11/13/2004 (5:23 pm)
Max has helped me out alot. I will probably still check that out to see what info it has to offer. thanks.