0 Favourites

How do I increase enemy speed per 10 sec

  • 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

  • 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

    .. Add 1 to SpeedInc

    System > Timer = 30

    .. Add 2 to SpeedInc

    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"

    .. Add SpeedInc to SpeedInc

  • 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.

  • 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

    .. Add 1 to SpeedInc

    System > Timer = 30

    .. Add 2 to SpeedInc

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

    On timer "SpeedInc"

    .. Add SpeedInc to 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?

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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

    .. Add 1 to SpeedInc

    .. Set enemy1.bulletspeed to SpeedInc * 100

    System > Timer = 30

    .. Add 2 to SpeedInc

    .. 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"

    .. Add SpeedInc to 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
111 91,104
lucasgc1's avatar
lucasgc1
Unread hot topic
74 47,271
WaterlooErik's avatar
WaterlooErik
Unread hot topic
71 9,087
janlindso's avatar
janlindso