How do I use multiple turret behaviors on the same object?

  • I'm making a space shooting game, and some spaceships have more than one type of projectiles, and those fire at different intervals.

    The simplest solution I came up with was to add a Turret behavior for each type on the family, and then enable/disable the turrets in each ship individually (as I have 120 different ships).

    Now the problem I'm facing is that if I have two different Turrets enabled on the same ship, with different Fire Rates, all of them are going to shoot using the first enabled turret's fire rate in the behavior list.

    How can I work around this? Or is there a way to do it without turrets?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Now the problem I'm facing is that if I have two different Turrets enabled on the same ship, with different Fire Rates, all of them are going to shoot using the first enabled turret's fire rate in the behavior list.

    How can I work around this? Or is there a way to do it without turrets?

    the more tedious and simplest way for you i think right now is to separate the turrets from the turret family and have individual targets and turrets with their own turret behavior. (the spacecraft don't need to be taken out of the family, but you would need for the turret to get as target the spacecraft name, and not the family of which the spacecraft is part of.) but you need to separate the turrets not having them in the same family.

    also would require your spacecrafts to be different sprite objects, and not different animations on the same sprite.

    this should fix your problem while still keeping the behaviors and family's to some extent.

    the other way around turret behavior is using distance(x1,y1,x2,y2) and compare for each spacecraft set angle towards it etc manually code the turret behavior with events basically.

    however im not sure why you want the turrets to have different targets... as the games i played so far, they all shoot when have enemies in proximity. unless you wan't to have a turret for long range and one for close encounter. i would use distance for that.

    ah ... edited: i misunderstood, you have 120 spaceship using the same turret to shoot... my bad, i was thinking your doing some tower defense type of thing. in this case distance is your friend.

  • the more tedious and simplest way for you i think right now is to separate the turrets from the turret family and have individual targets and turrets with their own turret behavior. (the spacecraft don't need to be taken out of the family, but you would need for the turret to get as target the spacecraft name, and not the family of which the spacecraft is part of.) but you need to separate the turrets not having them in the same family.

    Not sure I understand what you mean. For clarification, here is how it is all organized so far:

    Family: Spaceship

    Multiple Turrets with different Fire Rates.

    Family: Enemies

    Used as target for all of Spaceship's turrets, with a single turret behavior.

    Also, no enemies are in the spaceship family and vice-versa.

    also would require your spacecrafts to be different sprite objects, and not different animations on the same sprite.

    Already doing this, I have 120 different Sprite Objects in the same Spaceship family.

    the other way around turret behavior is using distance(x1,y1,x2,y2) and compare for each spacecraft set angle towards it etc manually code the turret behavior with events basically.

    I'm not currently using turrets for their range, but really for the timing. Tried with simple timers, but couldn't find an easy way to trigger it without an initial waiting period.

    however im not sure why you want the turrets to have different targets...

    I don't. I just want different fire rates, really.

  • ah ... edited: i misunderstood, you have 120 spaceship using the same turret to shoot... my bad, i was thinking your doing some tower defense type of thing. in this case distance is the way i would do it.

    for different firerates, you can use the family turret behavior for rotating and target.

    but the family turret behavior also is usable for each ship as a sprite object.

    not sure how you spawn your bullets/rockets. but as far as i remember the fire-rate of shooting using a turret it can be set manually or based on a variable, variable that can be different for each ship.

  • I think we are not understanding each other, allow me to clarify my problem...

    Let's say all my spaceships have two possobile weapons: a minigun and a missile launcher.

    The Minigun has a fire rate of 0.25 seconds and the Missile launcher has a 2 seconds fire rate.

    I have renamed the behaviors to Minigun and Missile, respectively, and am using "On Minigun shoot" and "On Missile shoot" events to spawn the bullets.

    The distance is irrelevant (set to a large value), and rotations are disabled for both (I'm controlling it manually).

    Both turrets are in the Spaceship family, toggled for each sprite needs (having one or both), and all of them have the Enemies family as target.

    My issue is that when I have both turrets enabled, the "On Missile shoot" event is currently being fired 4 times per second (fire rate of 0.25), when only the Minigun turret should.

    If I disable the Minigun turret, the Missile turret behaves as expected.

  • i think i understood now, i made you an example hope it helps xD im using 1 way of shooting though. but you can use more variables to trigger what type of weapon you are using range/firerate etc. just look at this example and you will understand what i think can be done :D

    Edited: i updated my capx, so you don't have to duplicate the actions as i did earlier.

    Edited2 : examplev2-2guns

  • Now I get what you meant. It's a nice approach, indeed.

    But in your demo, only one weapon can be used at a time. In my case, however, I want the spaceship that has Minigun and Missiles to both be used at the same time, with their respective fire rates. So that Minigun fires at 0.25 and Missile fires at 2.

    Using only one turret behavior is not possible at the time, I'm afraid. Unless I set some variable on shoot, and see if it's the 8th time it has been fired. This works, but when you get to 5 different weapon types with differing fire rates (which is my case), this get out of hand pretty quickly.

  • Now I get what you meant. It's a nice approach, indeed.

    But in your demo, only one weapon can be used at a time. In my case, however, I want the spaceship that has Minigun and Missiles to both be used at the same time, with their respective fire rates. So that Minigun fires at 0.25 and Missile fires at 2.

    Using only one turret behavior is not possible at the time, I'm afraid. Unless I set some variable on shoot, and see if it's the 8th time it has been fired. This works, but when you get to 5 different weapon types with differing fire rates (which is my case), this get out of hand pretty quickly.

    well not with 1 turret, but, if you have a spaceship and the guns are different sprites attached to the spaceship then you could use multiple turrets.

    for example spacecraft image with no guns , then u put minigun image attach it to it, and rocket launcher attach it to it, then each of those guns will be able to have different turret systems and firerates. but having multiple guns as a variable it's a bit tricky and overcomplicates things.

  • Sorry to jump in on this but I feel like you could've avoided using multiple turret behaviours on one object, which is confusing. You can instead use the turret behaviour, and based on an instance variable on the spaceship, determine the rate of fire and whether its firing a minigun projectile or a missile projectile.

  • well not with 1 turret, but, if you have a spaceship and the guns are different sprites attached to the spaceship then you could use multiple turrets.

    Have not thought of that. Great idea! Thank you.

    plinkie

    Didn't understand how that would work. Can you add some details, please?

  • Sorry to jump in on this but I feel like you could've avoided using multiple turret behaviours on one object, which is confusing. You can instead use the turret behaviour, and based on an instance variable on the spaceship, determine the rate of fire and whether its firing a minigun projectile or a missile projectile.

    that's what i did in my example but he has multiple guns that shoot at different rates, and at 120 ships with 2 guns or 5 guns each that is gonna make it hard to keep track of and a big database of firerates and ranges etc.i mean you would have a big spreadsheet of ranges and firerates no matter what, is more of how much you can simplify the management and tracking of all the data, as a beginner the bellow example should work fine, there are more advanced ways of doing this without even using the variables and behaviors, but that would require some xml knowledge, and coding the movement/shooting behavior by events.

    examplev3-2guns #case nr 2 - guns as separated objects.

  • Yeah like that latest example above, you can use instance variable on the spaceship to pick the weapon.

    If var=1, shoot minigun projectile, set firerate to 0.25

    If var=2, shoot missile projectile, set firerate to 2

    Then you set the variables at the point in the game where it needs to be decided which guns they are using, or you can alternate during the gameplay.

  • I am going to have to change a lot of things, but this is the best solution indeed. It will also allow for better customization of each shooting. This is what I needed. Thank you both for your help!

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