# How do I increase enemy speed per 10 sec

Get help using Construct 2

### » Tue Jun 06, 2017 1:17 am

So every 10 seconds I want to increase the enemy bullet speed by whatever number I choose. So I've done the basics. I've created a global variable called 'Timer', and inside the enemy I've created an instance variable called 'SpeedInc' with initial value of 0. The bullet speed for the enemy is setup at 100, at start of layout. Once the timer hits 10 sec, I changed the initial value to 1 for SpeedInc, which changes the bullet speed from 100 to 200. When the timer hits 10 sec, the enemies that spawn first DO increase their bullet speed, but the problem is is that, the new enemies that spawn later, their speed is at 100 and not 200. This is what I did:

System > Every 1.0 sec > Create object > enemy 1 > Set bullet speed 100 and Set bullet angle of motion 180.
Then I created a sub event:
System > Timer = 12 > enemy 1 > Set SpeedInc to 1 > Set bullet speed 200

I forgot to mention that I put the enemy 1 in a group. So in the event sheet it pretty much looks like this:

System > Timer = 10 > System > Set group enemy 1 activated
System > Every 1.0 sec > Create object > enemy 1 > Set bullet speed 100 and Set bullet angle of motion 180.
Then I created a sub event:
System > Timer = 20 > enemy 1 > Set SpeedInc to 1 > Set bullet speed 200
System > Timer = 30 > enemy 1 > Set SpeedInc to 1 > Set bullet speed 400
B
10
S
4
Posts: 20
Reputation: 840

### » Tue Jun 06, 2017 6:17 am

In your "Every 1 sec" you are hard coding the speed at 100, instead of rather using the value of the variable you are incrementing.

Also, the fact you are checking for "Timer = 20" will only work the moment your Timer value is equal to 20. As soon as your Timer is equal to 21, your speed will "revert" to 100.

You have kind of the correct idea of going about things but not correctly executed.

Global Variable Timer number Default value 0
Global Variable SpeedInc number Default value 1

System > Every 1 Sec
.. Create object > Enemy
.. Set bullet speed to SpeedInc * 100

System > Timer = 20

System > Timer = 30

For the Timer, you can also use the Timer behavior (set on Regular type) that could add SpeedInc value to itself every 10 secs
On timer "SpeedInc"
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
311
S
128
G
100
Posts: 7,413
Reputation: 74,722

### » Tue Jun 06, 2017 8:34 am

You can just use every 10 sec system expression, no need to complicate with timers, and other variables.

Also the new enemies that spawn will always have the default speed of the object, so you will have to add an action to change the speed as soon as the new object is created, this change will only effect the visible bullets on the screen, as soon as the bullet is destroyed its speed will be set to default.
Like my work? Fallow me on social media, and see my games on the arcade.
B
8
S
5
G
9
Posts: 298
Reputation: 5,402

### » Tue Jun 06, 2017 9:20 am

Message: TommyR can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Kyatric wrote:In your "Every 1 sec" you are hard coding the speed at 100, instead of rather using the value of the variable you are incrementing.

Also, the fact you are checking for "Timer = 20" will only work the moment your Timer value is equal to 20. As soon as your Timer is equal to 21, your speed will "revert" to 100.

You have kind of the correct idea of going about things but not correctly executed.

Global Variable Timer number Default value 0
Global Variable SpeedInc number Default value 1

System > Every 1 Sec
.. Create object > Enemy
.. Set bullet speed to SpeedInc * 100

System > Timer = 20

System > Timer = 30

For the Timer, you can also use the https://www.scirra.com/manual/167/timer Timer behavior (set on Regular type) that could add SpeedInc value to itself every 10 secs
On timer "SpeedInc"

Thanks for the response, but you lost me on the Global variable speed in default to 1. Would I still need to add an instance variable to each enemy?
B
10
S
4
Posts: 20
Reputation: 840

### » Tue Jun 06, 2017 10:54 am

@TommyR: SpeedInc is the value that handles the augmentation of the speed.
Having it as a global variable, you are sure that it raises on a regular basis. You also make sure that each new instance, when it's created, is applied the current speed (SpeedInc * 100).

I don't see the need for an instance variable here that would be different for each instance. Unless that's what you want to do, but as far as I understood your issue in the first post it wasn't about that. You wanted newly created instances to have a speed in relation to a value that evolves over time.

The bullet speed you talked about originally is about the speed at which bullets fired by enemy instances will travel ?
I assessed it was actually the moving speed of enemies instances, using the bullet behavior.

Perhaps you should explain clearly what is it you are looking to do exactly. We already know what you did, what you experience it does, we're missing the information of what you intended it to do actually do precisely.
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
311
S
128
G
100
Posts: 7,413
Reputation: 74,722

### » Tue Jun 06, 2017 11:51 am

Kyatric wrote:@TommyR: SpeedInc is the value that handles the augmentation of the speed.
Having it as a global variable, you are sure that it raises on a regular basis. You also make sure that each new instance, when it's created, is applied the current speed (SpeedInc * 100).

I don't see the need for an instance variable here that would be different for each instance. Unless that's what you want to do, but as far as I understood your issue in the first post it wasn't about that. You wanted newly created instances to have a speed in relation to a value that evolves over time.

The bullet speed you talked about originally is about the speed at which bullets fired by enemy instances will travel ?
I assessed it was actually the moving speed of enemies instances, using the bullet behavior.

Perhaps you should explain clearly what is it you are looking to do exactly. We already know what you did, what you experience it does, we're missing the information of what you intended it to do actually do precisely.

Layout size: 1920 x 1080
Global variable Timer: 0
Enemy1: Bullet behavior with bullet speed 100
Every 1 sec, enemy1 spawn

Once timer starts, spawn enemy1 with bullet speed of 100 (no issues with that).

Once timer hits 10 sec, is it possible to set all enemy1 speed to 200? The only enemy1 that changes it's speed to 200 are the new enemy1 that spawn on screen, while the old (enemy1) still on screen, still have the speed of 100.
B
10
S
4
Posts: 20
Reputation: 840

### » Wed Jun 07, 2017 10:35 am

Global Variable Timer number Default value 0
Global Variable SpeedInc number Default value 1

System > Every 1 Sec
.. Create object > enemy1
.. Set bullet speed to SpeedInc * 100

System > Timer = 20
.. Set enemy1.bulletspeed to SpeedInc * 100

System > Timer = 30
.. Set enemy1.bulletspeed to SpeedInc * 100

For the Timer, you can also use the Timer behavior (set on Regular type) that could add SpeedInc value to itself every 10 secs
On timer "SpeedInc"
.. Set enemy1.bulletspeed to SpeedInc * 100

As long as you use the same action when you spawn a new instance and when you raise the speed, all instances will have the speed applied to it, and so no need again for the instance variable, since all instances must end with the same speed.
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
311
S
128
G
100
Posts: 7,413
Reputation: 74,722