continuous machine gun fire when button is held down
by SlowDaddie · in Torque X 2D · 02/22/2010 (7:40 pm) · 4 replies
Hi,
Quick question for you all.
I'm not sure how to get a machine gun to fire continuously if the "fire" button is held down. I can get it to fire other weapons, one bullet at a time, each time the player presses the button, but a continuous burst of fire is kinda tricky so far.
Thanks in advance for any suggestions!
Quick question for you all.
I'm not sure how to get a machine gun to fire continuously if the "fire" button is held down. I can get it to fire other weapons, one bullet at a time, each time the player presses the button, but a continuous burst of fire is kinda tricky so far.
Thanks in advance for any suggestions!
#2
That looks like it'll get the job done. Thanks!
That being said, is that the only way to accomplish this?
I'm presently using the inputMap.BindMove functionality to map several different buttons to fire (Space on windows, Shoulder Triggers on a 360 Controller), as I was hoping to maintain some level of platform agnosticism.
What I've currently got is more or less the following:
I was hoping there was some way to use the ProcessTick's move parameter to figure out if the button is still held(as Pushed seems to only provide the "just pushed" functionality).
But again, if this isn't doable, your way seems like it'll work great.
Thanks again!
02/22/2010 (9:52 pm)
Hi Patryck.That looks like it'll get the job done. Thanks!
That being said, is that the only way to accomplish this?
I'm presently using the inputMap.BindMove functionality to map several different buttons to fire (Space on windows, Shoulder Triggers on a 360 Controller), as I was hoping to maintain some level of platform agnosticism.
What I've currently got is more or less the following:
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.LeftTriggerButton, MoveMapTypes.Button, 0);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.RightTriggerButton, MoveMapTypes.Button, 0);
inputMap.BindMove(keyboardId, (int)Keys.Space, MoveMapTypes.Button, 0);
.....
public virtual void ProcessTick(Move move, float dt)
{
if (move.Buttons[0].Pushed)
{
Fire();
}
}I was hoping there was some way to use the ProcessTick's move parameter to figure out if the button is still held(as Pushed seems to only provide the "just pushed" functionality).
But again, if this isn't doable, your way seems like it'll work great.
Thanks again!
#3
For example
(the held part of the code is so I know how long the button was held down fighting game stuff).
02/22/2010 (11:29 pm)
Your if statement should test as true as long as the button is held. I use interfaces but my button code looks like this and the "else" part of the statement only returns if the button is released.For example
//button 1 pressed
if (move.Buttons[1].Pushed)
{
I1ButtonPressed.Value = true;
I1ButtonHeld.Value += 1;
}
else
{
I1ButtonPressed.Value = false;
I1ButtonHeld.Value = 0;
}(the held part of the code is so I know how long the button was held down fighting game stuff).
#4
I did some tests, following your advice, and I found something really strange.
I moved my Bindmoves from Button[0] to Button[3] (I'm already using 1 and 2), and my continuous fire began work just as I'd intended.
For the sake of clarity, here's what my (now functional) code now looks like.
Thanks again for the advice!
02/23/2010 (12:17 pm)
Hi Matthew, thanks for the reply.I did some tests, following your advice, and I found something really strange.
I moved my Bindmoves from Button[0] to Button[3] (I'm already using 1 and 2), and my continuous fire began work just as I'd intended.
For the sake of clarity, here's what my (now functional) code now looks like.
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.LeftTriggerButton, MoveMapTypes.Button, 3);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.RightTriggerButton, MoveMapTypes.Button, 3);
inputMap.BindMove(keyboardId, (int)Keys.Space, MoveMapTypes.Button, 3);
.....
public virtual void ProcessTick(Move move, float dt)
{
if (move.Buttons[3].Pushed)
{
Fire();
}
}Thanks again for the advice!
Torque Owner Patryck Pabllo
I think you can add a code like above in processTick method of your fire component:
int elapsedTime;
public virtual void ProcessTick(Move move, float dt)
{
if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
elapsedTime += Game.Instance.Engine.GameTime.ElapsedRealTime.Milliseconds;
if (elapsedTime > 200) //it creates 5 fires per second
{
CreateNewFire();
elapsedTime=0;
}
}
}