get an enemy to return fire after being hit

0 favourites
  • 7 posts
From the Asset Store
Game "Little Dino Adventure Returns" with complete Source-Code (Construct3 / .c3p) + HTML5 Exported.
  • Hi,

    First time poster, first time Construct 2 users, basically a newb.

    I'm currently working with the "Template: Real Time Strategy (RTS)" template. It's excellent for learning from.

    I've modified the Event sheet to prevent Friendly and Enemy units from attacking each other (disabled both actions in event 2) and I've made it so that my (selected) Friendly units will only attack Enemy units I click on (inserted a new event under 16 that on mouse left click of an enemy a Friendly target will 'acquire' the enemy). This all works well, and being my first attempt I was surprised at how simple it was <img src="smileys/smiley1.gif" border="0" align="middle" />

    My problem: I want the Enemy I'm attacking to engage the first Friendly it received fire from - returning fire.

    I've tried a number of things but I just can't get my head around how to get the enemy to acquire the specific Friendly object that shot it first.

    I've read a number of FAQ's on Picking/selecting instances, nothing really helped me.

    Any help appreciated.

    /Jamie

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • hrm... found a bug - even if my Friendly units aren't selected they will shoot at (not move) an enemy unit I click on.

    Behaviour should be only to engage an Enemy unit if the Friendly is selected.

    Investigating...

    EDIT

    Resolved this by adding another condition to my new event (described in original post) to make sure a Friendly is selected (using the already defined IsSelected var).

    EDIT 2

    Strike that, 1/2 resolved. If nothing is selected then there is no action. Sweet!

    When I have 1 Friendly unit selected and attack a close by Enemy unit, all friendly units attack but any unselected don't move.

    I think it's still my 'new' event, which is;

    On Left button Clicked on EnemyBases AND FriendlyBases is IsSelected

    {

    EnemyBases: Set IsTargeted to True

    FriendlyTurrets: Turret acquire target EnemyBases

    }

    Pretty sure "FriendlyTurrets: Turret acquire target EnemyBases" tells ALL FriendlyTurrets to acquire the Enemy... not just the selected instance.

    EDIT 3

    3/4 Resolved. I disabled the suspect action and added a sub-event to pick a specific instance of a FriendlyTurret based on the TurretUID stored as a var in the FriendlyBase.

    It worked!

    On Left button Clicked on EnemyBases AND FriendlyBases is IsSelected

    {

    EnemyBases: Set IsTargeted to True

    Pick instance with UID FriendlyBases.TurretUID

    {

        FriendlyTurrets: Turret acquire target EnemyBases

    }

    }

    Side-effect: if I select multiple FriendlyBase only the first selected will shoot... think I need to set a new var and throw an ELSE and/or FOR in somewhere

    Investigating...

  • a much simplified version of what I think you are after

    capx

  • hrm... I'm getting an error telling me;

    ---------------------------

    Unable to load project

    ---------------------------

    Could not open project because it is from a newer version of Construct 2. The project was saved in release 162 or newer. Your current release is 158.2. Try downloading the latest version of Construct 2 to open this project.

    ---------------------------

    OK   

    ---------------------------

    The version on the site is 158.2?

  • The last version (beta) is 162 : scirra.com/construct2/releases/r162

    The stable is 158.2 :)

  • At the very bottom of the page, you will see a link to download the latest beta, r162. Most people update quite often, and you can use this version too if you want to open RamPackWobble's file.

  • Cheers Joskin and Guizmus.

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