Game Development Community

Preventing weapon fire when underwater

by Ronald J Nelson · in Torque Game Engine · 12/08/2007 (8:56 pm) · 3 replies

I want to prevent my weapons from firing when underwater. Has anyone else done this that can throw me a pointer?

I don't know if any of you caught that MythBusters episode, but unless you are shooting a small high velocity round, the bullet pretty much stops almost immediately in water, it might get a few feet. I have modified my code so it just explodeds on the surface of the water. It does look a lot better. I just want to prevent firing while underwater.

Thanks for any help you can give me.

#1
12/09/2007 (6:00 am)
This is a stock feature in the Torque weapon states. You need to do a "CheckWet" call before going into the fire state. This will automatically check whether the player is submerged in water or not, if they are then the fire state never gets called.

I don't have time to break this down for you but if it helps here's an old state system of one of my sniper rifles. Some of it is custom stuff that won't be relevant so you'll need to filter that out.

// 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.7;
   stateSequence[1]                 = "Activate";
   stateSound[1]                    = WeaponUseSound;

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

   stateName[3]                     = "Fire";
   stateEjectShell[3]               = true;
   stateSound[3]                    = M24FireSound;
   stateTransitionOnTimeout[3]      = "FireEnd";
   stateTimeoutValue[3]             = 0.3;
   stateFire[3]                     = true;
   stateAllowImageChange[3]         = false;
   stateSequence[3]                 = "Fire";
   stateScript[3]                   = "onFire";

   stateName[4]                     = "FireEnd";
   stateTransitionOnTimeout[4]      = "Ready";
   stateTimeoutValue[4]             = 0.25;
   stateAllowImageChange[4]         = true;
   stateSound[4]                    = ShellSound;

   stateName[5]                     = "Reload";
   stateScript[5]                   = "onReloadState";
   stateSequence[5]                 = "Reload";
   stateEjectShell[5]               = true;
   stateTransitionOnTimeout[5]      = "Ready";
   stateTimeoutValue[5]             = 4.0;
   stateAllowImageChange[5]         = false;

   stateName[6]                     = "CheckWet";
   stateTransitionOnWet[6]          = "DryFire";
   stateTransitionOnNotWet[6]       = "Fire";
   
   stateName[7]                     = "NoAmmo";
   stateScript[7]                   = "onReload";
   stateTransitionOnAmmo[7]         = "Reload";
   stateSequence[7]                 = "NoAmmo";
   stateTransitionOnTriggerDown[7]  = "DryFire";
   
   stateName[8]                     = "DryFire";
   stateTimeoutValue[8]             = 0.5;
   stateTransitionOnTimeout[8]      = "Ready";

   // Play the weapon bob animation
   stateName[9]                     = "Bob";
   stateTransitionOnTimeout[9]      = "Ready";
   stateTransitionOnTriggerDown[9]  = "Fire";
   stateTimeoutValue[9]             = 0.70;
   stateAllowImageChange[9]         = true;
   stateWaitForTimeout[9]           = false;
   stateSequence[9]                 = "Bob";

   // Play the idle animation
   stateName[10]                     = "Idle";
   stateTransitionOnTimeout[10]      = "Ready";
   stateTransitionOnTriggerDown[10]  = "Fire";
   stateTimeoutValue[10]             = 0.85;
   stateAllowImageChange[10]         = true;
   stateWaitForTimeout[10]           = false;
   stateSequence[10]                 = "Ready";

   // Lower the gun. Called when sprinting
   stateName[11]                     = "Sprint";
   stateTransitionOnTimeout[11]      = "Sprint";
   stateTimeoutValue[11]             = 0.7;
   stateSequence[11]                 = "DeActivate";

Hope that helps.
#2
12/09/2007 (10:20 am)
Thanks Tim!
#3
12/09/2007 (11:56 am)
Cool now my rocket launcher doesnt fire underwater, but the bubblemaker does/.. :)

TomFeni