Creating non-automatic weapon firing?
by Jeff Murray · in Technical Issues · 08/16/2006 (1:08 pm) · 8 replies
Ello all!
I'm building a game which has different types of weapons (some automatic and some manual). I can see that the onFire function is called from the states of the weapon, which makes sense because I can syncronise the firing with the animation, but I wonder if anyone has any idea what would be the best way to go about stopping the fire repeat when you hold down the mouse button on non-automatic weapons?
I *could* have the timeouts in the states higher, but I need the players to be able to tap the mouse pretty quickly to fire off lots of rounds. It's more about stopping the repeat that I can't figure out!!
Just a couple of pointers in the right direction would be good :) as I'm still figuring my way around in here...
Thanks in advance for any help you guys can give me,
Jeff.
I'm building a game which has different types of weapons (some automatic and some manual). I can see that the onFire function is called from the states of the weapon, which makes sense because I can syncronise the firing with the animation, but I wonder if anyone has any idea what would be the best way to go about stopping the fire repeat when you hold down the mouse button on non-automatic weapons?
I *could* have the timeouts in the states higher, but I need the players to be able to tap the mouse pretty quickly to fire off lots of rounds. It's more about stopping the repeat that I can't figure out!!
Just a couple of pointers in the right direction would be good :) as I'm still figuring my way around in here...
Thanks in advance for any help you guys can give me,
Jeff.
#2
08/16/2006 (3:23 pm)
Paul, Jeff says that he actually wants the user to "be able to tap the mouse pretty quickly to fire off lots of rounds". I dont think he can use timeout for his purposes. if you want to prevent rapid fire theres probably a number of ways to do this including changes to the source code. i think the best way would be to add a bit of logic to the onfire script and add a script for the onTriggerUp event. if the weapon doesnt support rapid fire, the onFire script should have a condition which checks a global variable. if the value is true, fire the projectile and change the variable to false, otherwise dont do anything. like Paul said, use the onTriggerUp event to call a different script which will change the global to true so the next time onFire is called the projectile will be fired again. this way, although onfire will still continuously be called while the mouse is pressed, the projectile wont fire again until onTriggerUp has been called.
#3
:) Sounds like a solution! Is there a list of events for the weapon state machines anywhere? I did a search around the site, but didn't come up with anything other than forum posts.
Anyhoo ... once again, this community rocks!
08/16/2006 (5:43 pm)
Thanks, guys! I'll go think about that for a bit (initial reading caused brain pop after long day!!) ... :) Sounds like a solution! Is there a list of events for the weapon state machines anywhere? I did a search around the site, but didn't come up with anything other than forum posts.
Anyhoo ... once again, this community rocks!
#4
Anyways, don't listen to what Sean said, it's not that complicated. At the most basic level, you make the only condition for going from your Fire to Ready state be onTriggerUp. If that is the only way to go back to the ready state, you can't fire again until you've release the trigger.
08/16/2006 (6:23 pm)
I'm not sure if there's already a list of the states somewhere, I think doing a .dump() might get you them. Here's the list straight from source anyways."stateName" "stateTransitionOnLoaded" "stateTransitionOnNotLoaded" "stateTransitionOnAmmo" "stateTransitionOnNoAmmo" "stateTransitionOnTarget" "stateTransitionOnNoTarget" "stateTransitionOnWet" "stateTransitionOnNotWet" "stateTransitionOnTriggerUp" "stateTransitionOnTriggerDown" "stateTransitionOnTimeout" "stateTimeoutValue" "stateWaitForTimeout" "stateFire" "stateEjectShell" "stateEnergyDrain" "stateAllowImageChange" "stateDirection" "stateLoadedFlag" "stateSpinThread" "stateRecoil" "stateSequence" "stateSequenceRandomFlash" "stateSound" "stateScript" "stateEmitter" "stateEmitterTime" "stateEmitterNode" "stateIgnoreLoadedForReady"MaxStates);If you don't understand what it does from the name of the state, it's probably some weird Tribes 2 holdover that doesn't matter anyways.
Anyways, don't listen to what Sean said, it's not that complicated. At the most basic level, you make the only condition for going from your Fire to Ready state be onTriggerUp. If that is the only way to go back to the ready state, you can't fire again until you've release the trigger.
#5
Thanks for the help again :)
08/17/2006 (6:16 am)
I'm so impressed by this community ... I post a question and almost always get helpful replies within a day. It's awesome! I'm really loving Torque right now and with your help my game is coming together better than I could have thought.Thanks for the help again :)
#6
what do these states define, or in what situations are they set:
or are these even used?
08/17/2006 (8:54 am)
Well while this is here I might as well ask about some of those states that are listed. I don't own the source so, for right now at least, there's no way for me to understand what the default states do. i can guess what most do but some look foreign to me.what do these states define, or in what situations are they set:
"stateTransitionOnTarget" "stateWaitForTimeout" "stateFire" "stateEjectShell" "stateEnergyDrain" "stateDirection" "stateLoadedFlag" "stateSpinThread" "stateSequenceRandomFlash" "stateEmitter" "stateEmitterTime" "stateEmitterNode" "stateIgnoreLoadedForReady"
or are these even used?
#7
Just incase anyone needs a rapid-firing weapon that involves a lot of clicking (!) I thought I'd share it ...
Unfortunately (I have no idea why) none of my particle systems appear to work right now (broken elsewhere in code earlier!!), which is why I don't have any fancy emitters in there ... hopefully I'll be able to get them working soon so I can have some smoke come out the front of the gun when it fires. For now though, this might server as a good start for someone who wants to do a similar kind of gun.
:)
08/17/2006 (9:29 am)
Thanks again for the help ... it works perfectly! I switched the states around as you said Paul and got it to fire really rapidly but without repeat :) Exactly as I needed.Just incase anyone needs a rapid-firing weapon that involves a lot of clicking (!) I thought I'd share it ...
// 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.001; // Ready to fire, just waiting for the trigger stateName[2] = "Ready"; stateTransitionOnNoAmmo[2] = "NoAmmo"; stateTransitionOnTriggerDown[2] = "Fire"; stateSequence[2] = "Ready"; stateTimeoutValue[2] = 0.001; // Fire the weapon. Calls the fire script which does // the actual work. stateName[3] = "Fire"; stateFire[3] = true; stateRecoil[3] = LightRecoil; stateAllowImageChange[3] = false; stateSequence[3] = "Fire"; stateScript[3] = "onFire"; stateSound[3] = PBGFireSound; stateTransitionOnTriggerUp[3] = "Refire"; stateEmitterTime[3] = 3.001; // Go straight to refire so we can fire faster stateName[4] = "Refire"; stateTransitionOnNoAmmo[4] = "NoAmmo"; stateTransitionOnTimeout[4] = "Ready"; stateTimeoutValue[4] = 0.0001; stateAllowImageChange[4] = false; // 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"; stateTimeoutValue[6] = 0.0001; // No ammo dry fire stateName[6] = "DryFire"; stateTimeoutValue[6] = 0.0001; stateTransitionOnTimeout[6] = "NoAmmo"; stateSound[6] = PBGFireEmptySound; // Play the reload animation, and transition into stateName[7] = "Reload"; stateSequence[7] = "Reload"; stateTransitionOnNoAmmo[7] = "NoAmmo"; stateTransitionOnTimeout[7] = "Ready"; stateTimeoutValue[7] = 3; stateAllowImageChange[7] = false; stateSound[7] = PBGReloadSound;
Unfortunately (I have no idea why) none of my particle systems appear to work right now (broken elsewhere in code earlier!!), which is why I don't have any fancy emitters in there ... hopefully I'll be able to get them working soon so I can have some smoke come out the front of the gun when it fires. For now though, this might server as a good start for someone who wants to do a similar kind of gun.
:)
#8
now any suggestions about my question? any resources which describe the states i mentioned above?
08/17/2006 (10:24 am)
Nice work Jeff. for some reason I was thinking that the ontriggerup event was used to execute a script rather than a state transition. it really was alot easier than i thought.now any suggestions about my question? any resources which describe the states i mentioned above?
Torque Owner Paul /*Wedge*/ DElia