Open question about Turret timing

0 favourites
  • 6 posts
  • So I wanted to see if any of you smart people here had any suggestions on doing something:

    Say the game is a tower defense game but the different towers would shoot at different intervals ( 1 tower every .5 seconds, another tower every 1 second)..BUT I want them to be in sync with the timing right from when someone clicks start after putting the towers down.

    So the complication is, this fire rate really isn't using the timing until an object gets into its path THEN starts saying ok, every .5 seconds ill shoot. But then that wont be in sync with one that gets a target in it's sight .7 seconds after the other turret does because THEN it starts saying ok every 1 second I shoot. I don't know if I'm explaining this well but I'm tryin.

    So I guess the question is, how would you guys write the code to make sure the tower's are always on the same timing even when there are no targets available to shoot at?

  • You could create an independent timer for every turret with a different fire rate:

    Something like this: TurretTimings.capx (r117)

  • Awesome!

    Ok, so I program in multiple languages but for some reason some of the logic you made is confusing me (I thought I was doing well in Construct2! geez). What exactly is the Max(0,r-dt) doing? I know the dt is delta time and the r is the variable but I'm a bit lost.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • By subtracting dt every tick your timer decreases with 1 every second, also taking into account the framerate.

    The max expression just stops the value from going below 0, so what you get is a timer that starts at r0 and decreases by 1 every second until it reaches 0.

  • Ah thanks for that Nimtrix, Ive been looking into dt a bit the past few days and trying to get used to it.

    Here's the dilemma, say at the start of a "level" I set a time to say 2 minutes. The shooting from the turrets I want to ALWAYS shoot at their designated second variable (every .5 seconds, 1 second, etc), BUT to only actually shoot a bullet when an enemy is in it's "range". The problem is that trying to mess with the example you sent me I could mimick that but the turrets ended up getting out of sync a bit.

    So do you see an easy way with some more complicated expressions to do this:

    Timer = 120 seconds

    Every tick subtract dt from Timer.

    Tower 1 Shoot bullet when Timer is x.5 seconds AND enemy is in x range

    Tower2 Shoot bullet when Timer is a whole 1 second AND enemy is in x range

    What this really comes down to is wherever the tower is and whatever is happening, if a bullet is supposed to come from Tower 1 and Tower 2 that they shoot at the exact time.

    Sorry I'm not really giving really in depth details about the game because honestly I'm worried about others liking my idea and running with it (no offense to anyone), but I really want to make this game. So if your bored and cant think of anything from these details I wouldn't mind brainstorming through messages if your bored.

    Thanks Nim and anyone else that has ideas on trying this!

  • Hey DjFuzion,

    There is an old example from Rojohound about turrets that I found really helpful a while back (I think if you check in Kyatrics faq it should still be there).

    Basically though, the way it works is all your turrets have a reverse timer - so that when they fire an individual timer on that sprite starts to count down.

    Sorry I dont have the time to bang up an example but what I would try is: when a turret shoots you would want to add a condition to pick all of the same turrets and instead of setting the timer just to that one, you set it to all of them. This should allow all of your turrets to shoot in unison.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)