Turret behavior and priority levels

This forum is currently in read-only mode.
From the Asset Store
Unlock Levels, Worlds & skin plus add coins by watching ads
  • I'm making a tower defense game and i'm using the turret behavior for it. It works just fine, but I want to add some more to it.

    There's going to be some buildings that the player may build towers nearby to destroy, but I want the towers to give priority to walking enemies, so they will only shoot the buildings if there is no walking enemy in range

    <img src="http://i54.tinypic.com/155kuoj.gif">

    Black: building that is being shot by blue turret

    Blue: will switch targets if red walks in range

    Red: is higher priority than black

    This is the "get target" event

    <img src="http://i56.tinypic.com/30djiax.gif">

    Both walking enemy and building are in the "Enemy" family

    "Items" family is the turret family

    I tryed giving each enemy a "priority" variable, and tell turret to "pick Enemy with highest 'priority'", but that did nothing. It just locks on the building untill it's destroyed

  • It seems that the "Add target" action selects from all the "enemy" type not just the currently selected enemy.

    A solution would be to add the object type of the selected object as a target instead of the family.

    Edit the "Add Target" action and right click "object to target" and select use expression. Now you can choose an object by their OID (object id), which is different for each object type. Next type in "Enemy.OID". The "OID" expression with families returns the OID of of the actual object, not the family.

  • You say like this?

    <img src="http://i56.tinypic.com/ofatf4.gif">

    Still doesn't work (with and without the "pick with highest priority" event)

    ---

    And I have another question. Why can't I create an object and set it's variables right after it's creation? (btw, i'm using families for this too)

    If I have something like

    Every 1000 miliseconds > Create object by name "object"
                           > Set "family" "health" to 100[/code:3kqhidbd]
    Then it will set the health of all "object" at once, not only the one just created
    I have to set the health of the object's family because I don't know which object is being created, all I know is that it belongs to the family
  • bump

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To your first issue: The 'Else'-event is not working. This is because it is a subevent of for each. 'Else' needs to be on the same level than the event you want to branch. That means, the targets never get cleared, just new targets added. You can't work with 'else' here. I would show you an alternative, but I am not sure, under what condition exactly you want to clear the targets.

    To the second issue: Creating an object puts it on the SOL, instead of

    Set "family" "health" to 100

    just do

    Set object('health') to 100

    and the correct object will automatically be used. If the object is a sprite, then you're out of luck. Sprites are created at the end of a tick, you can't access a pv until the next tick. One way would be to store Sprite.OID or UID in a variable after having created it and do a check for that variable holding a value before that variable was filled with OID or UID. If it contains a value, select the object based on the OID or UID and set its pv. Just make sure those events are all placed before creating the object and storing its OID. The variable may be a pv or a global, but it must not be a pv of the newly created object.

  • I want to check for higher priority every time. So if the turret is shoting a low priority object and a high priority object comes in range, it should switch targets to the one with higher priority

    2nd issue: well that sucks, but i've found a workaround for that, thx

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