Game Development Community

3 more weapons mounted on a vehicle

by Edward · in Torque Game Engine · 03/29/2007 (8:19 am) · 3 replies

Greetings, im working on creating a add on for the tank pack, a TOW missle or possible second machine gun nest mounted on top of the existing turret. Now the tank has the main gun and the secondary gun, which is operated using the mouse trigger 1 and mouse trigger 2, these are mounted on mount 0 and function properly up until i mount the 3rd weapon, which i placed on mount 5.

now this is where it gets wierd, the player mounts fine, but the secondary weapon no longer fires, instead the 3rd weapon fires, the 1st mouse still fires the main gun, but the 2nd weapon trigger got transfered to the 3rd weapon. I added in a command to server for the 3rd weapon, but it seems to be returning a error.

be aware, this code is based off the crossbow, and is lengthy and edited for content.
for the most part crossbow has been replaced by TOW.

datablock ShapeBaseImageData(TOWLauncherImage)
{
// Basic Item properties
shapeFile = "~/data/shapes/crossbow/weapon.dts";
emap = true;

// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 5;
Offset = "0.0 0.0 1.0";
correctMuzzleVector = false;
className = "WeaponImage";

// Projectile && Ammo.
item = TOWLauncher;
ammo = TOWAmmo;
projectile = TOWProjectile;
projectileType = Projectile;

...

//-----------------------------------------------------------------------------

function TOWLauncherImage::onFire(%this, %obj, %slot)
{
%projectile = %this.projectile;
%obj.decInventory(%this.ammo,1);
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));

// Create the projectile object
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}

function serverCmdfireMissle(%client)
{

%client.player.onFire(TOWProjectile,%client,0);
}

moveMap.bindCmd(keyboard, "m", "commandToServer(\'fireMissle\');", "");


The weapon currently fires, usingthe mouse, and the keybind isnt working. other then the loss of the secondary weapon, it works normally.

About the author

I am working on my first large Game with a team of programmers and artists. I am a avid gamer and am the lead producer and director of Fantasci Hidden War. I have my first published game credit with Chariots as a Level Designer and Interior Artist.


#1
03/29/2007 (8:42 am)
As I see it your problem is that (out of the box) Torque only supports two firing triggers (typically mouse button 0 and 1).

You can mount as many weapons to your tank as you want but they will all have to fire from one of those buttons.

For example:

- You could mount three machine guns and two rocket launchers to your tank. The three machine guns would all have to fire at the same time with the left mouse button and the two rocket launchers with the right. Or, you could script it so that pressing the right mouse button fires rocket launcher one, then when pressed again rocket launcher two fires. There actually a few other combinations you could do, but the point is you only have two buttons (firing triggers) to work with.

Also, this piece of code is wrong on so many levels and I'm too tired to go into it right now:
function serverCmdfireMissle(%client)
{
   %client.player.onFire(TOWProjectile,%client,0);
}

Best approach is to mod the source code to handle more than two firing triggers. You could do it in script with a bit of hackery though if that's more your style.
#2
03/29/2007 (9:42 am)
Hmm i understand, im looking something onthe way of the way the instant grenade resources works, where you press a button and it throws a grenade. I dont want it to be triggered like a standardized weapon.

This is the issue, it recognizes it as a weapon which while i do, i dont want it to be recognized as a mouse control. Maybe if i create is as a AI? it is going to have the guided already as soon as i can get the keystroke problem figured out.

Has anyone found a solution similiar to what tim is talking about or a example piece of code that can be adapted. it seems 99% of the people have avoided the issue but limiting mounted weapons to chains and such. so not in the way for forums. I know you can swap weapons out, but that would just look "wierd" on top of a abrams, while it might give me a option, that canceles out the other weapons while the missle is active.... Hmm which give me a idea. Still i would like any thought or suggestions if anyone has one. I can get you a screenshot when i return to my home computer.

on that note. maybe i could mount it as a seperate turret, though would i have the same limitations? im not sure how to isolate this weapon to be the sole weapon to be fire, (its a major weapon, with very few uses; and a big boom :P)