Salvos for the turret behaviour

New releases and general discussions.

Post » Mon Jan 26, 2009 11:22 am

Just a small suggestion.
I'm sure this can be done using events, but it would be great if the turret behaviour could fire in salvos, i.e. three quick shots, then reload. This is quite a common behaviour in games with turrets.

I implemented something like this in a game maker game, but it required several variables and nested if statements to make it work properly.

It could be implemented using two variables - salvoSize and salvoInterval (or similar). These could work in tandem with the other variables and properties of the turret. So if the onShoot event fires, the turret would automatically shoot {salvoSize} bullets with {salvoInterval} milliseconds between them, then wait for it's standard reload time before firing again.

Any thoughts?
B
2
S
2
G
3
Posts: 105
Reputation: 1,510

Post » Mon Jan 26, 2009 12:49 pm

Its already set to do this easily.
You can add additional image points to your sprite, then on the on shoot event trigger the projectiles you can use time.delta for each create bullet at image point.
1 event 3 actions, you could probably use a loop or even a for each in there.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon Jan 26, 2009 12:55 pm

I see. I didn't realise image points could be used in that way.
I'll give this a go next chance I get.

I assume the same techniques could be used to create spray and other bullet arrangements?
Thanks.
B
2
S
2
G
3
Posts: 105
Reputation: 1,510

Post » Mon Jan 26, 2009 1:14 pm

Image points are unlimited as far as I know.
You can do single, double, triple, etc, even a machine gun, or shot gun effect.
Your limited more by hardware more that software here.
One quick hint, the collision event "object collides with object" is a little bugged atm, so use "object is overlapping".
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Tue Jan 27, 2009 4:56 pm

Ah so instead of just having a single shot, the turrets have ammo...so there'd be like a 'between shots' time and a 'reload time' and 'ammo'?
B
4
S
2
G
5
Posts: 641
Reputation: 3,011

Post » Tue Jan 27, 2009 6:00 pm

Not sure about the "between shots", but lowering the reload time gives the rapid fire.
Then if you want a set amount of ammo, you could easily add a private variable to the object, then just subtract it on the on shoot event.

I suppose on the "between shots" if you mean like separate sprays of fire, you could add:
On sprite shoot
Every x ticks
> sprite create object
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Tue Jan 27, 2009 11:29 pm

This is the code I used in to make this work in GameMaker, after hacking away at it for an entire night:

[code:3kwc4jy7]
if(firing==true) {
if(shots>0) {
if(reload==5){
s=instance_create(x, y, obj_enemyShot);
s.direction=direction;
s.speed=4;
shots-=1;
reload=0;
if (shots==0) alarm[0]=30;
}
} else {
firing=false
}
}
if(reload<5) reload+=1;[/code:3kwc4jy7]

Prior to this is code that makes it rotate and decide whether or not to fire (firing=true). This code is executed every step, using GM's fixed time step (30fps). So, first check if the cannon is firing, then if it has ammo (shots > 0). Then check if the cannon is loaded (reload==5), and if so, fire a bullet in the direction the cannon is facing, reduce the shots available and start the reload cycle. When you run out of shots, start the timer (alarm[0]) to do a full reload. The alarm event has code to set shots back to 3.

Horrible code, I know. But the end result was a really nice turret that tracked the player and fired off a salvo of 3 bullets, 1/6seconds apart, with a 1 second gap between salvoes. Much nicer that an endless stream of bullets. This is the sort of thing I was trying to describe.

As I said, I'm sure something like this could be done using events. It's a question of whether it is significant enough to warrant adding to the behaviour. It doesn't look like it would be used enough to make adding it worthwhile. Case closed.
B
2
S
2
G
3
Posts: 105
Reputation: 1,510

Post » Wed Jan 28, 2009 12:37 am

It's not so difficult to make in Construct as it is in GM :)

http://willhostforfood.com/files3/7051053/salvo.cap

Just four events, makes use of the Function object and "Call function after delay."

The turret behavior doesn't fire constantly though, which you would expect if they're firing in salvos. If the target moves beyond the angle at which the turret "Has target" then the turret won't fire. Seems to me that the Turret could benefit from some new features (no need to give Platform all the new features, guys :P). Something like:

Ammunition [Amount]
Fire Rate [In milliseconds]
Constant Fire [Checkbox] (if target is within the Range limit)

Then "Reload time" would kick in after Ammunition is depleted. That way you could have separate fire rates and reload times, which is the sort of thing you need for something like this. But then again maybe it's not all that necessary, considering it can be done in a few events.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Jan 28, 2009 9:52 am

My first turret in GM worked like yours - only firing when the player was in it's field of fire, so it would sometimes only fire two shots, then fire the last one the next time the player came in range.

The code above was a fix for that problem. By using the 'firing' variable, and toggling the variable when the shots were depleted, I ensured that the entire salvo was fired in one continuous burst. This gave me the more realistic anti-aircraft style firing. When you attach a sound to that action the effect is really nice: boo-boo-boom!

I'm now positive that such behaviour could be done using events, but is it the sort of thing that would be better implemented in the behaviour?
B
2
S
2
G
3
Posts: 105
Reputation: 1,510

Post » Wed Jan 28, 2009 11:00 am

[quote="GMG":3is2jwxb]is it the sort of thing that would be better implemented in the behaviour?[/quote:3is2jwxb]

Tough to say. Ultimately, it's down to the developer's judgments on that, and they don't always make their intentions known :P. It seems to me that adding Ammunition, Fire Rate, and Constant Fire would be useful, though.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 3 guests