Enemies targeting each other

This forum is currently in read-only mode.
From the Asset Store
Pixel Enemies for SHMUP
$3.50 USD
30% off
Pixel Enemies for SHMUP consists of 45 enemy ship sprites to be used in your game.
  • Hello again!

    I am having several issues with having one object pick another instance of itself. What is supposed to happen is that it picks whatever is closest to it that is not itself, but a bunch of horrible things happen and I am just absolutely confused...

    I've tried several workarounds and nothing seems to work. I tried having a second object to always be at its owner, and have them target that, but it doesn't stick with them like it's supposed to.

    I'll make a cap with all the things I've tried, but it will take a minute...

    And again, thanks for the help!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i got a way around this problem using a separate object, if your still having troubles with this let me know and I'll put together a .cap for you.

  • Try setting a global variable EnemyX and EnemyY to the current enemy X and Y and then above the "pick closest [enemyobj]" condition try adding this one "Compare two values: distance(EnemyX, EnemyY, [enemyobj].X, [enemyobj].Y greater than 5".

    This will then pick the closest enemy object that is not within 5 pixels of the current enemy object (in theory, haven't tested yet)

    Edit: Oops, choose "Pick by evaluate" for the enemyobj and compare the distance instead of "Compare".

    Double edit: Here's my testing cap https://dl.dropbox.com/u/4714446/SelfTarget.cap

    Hope that helps! <img src="smileys/smiley4.gif" border="0" align="middle">

    (Note: the red object shown doesn't do anything but show which object is being targeted. It can be deleted entirely and the code still works <img src="smileys/smiley1.gif" border="0" align="middle">)

  • https://www.dropbox.com/s/pkd9oms7fralzv5/ships%20fighting%20ships.cap

    I didn't spend any time cleaning it up but here's a .cap of the same objects belonging to different "teams".

  • *post*

    This helps, however it's not exactly what I had in mind; My goal is to have each enemy have its own target, and aim at it, which means I need to use Private Variables. And by using Private Variables, the picking will get messed up like before.

    *post*

    This is more of what I had in mind (and looks rather fancy!), but each single enemy would be its own team, and considering that each team has its own special object (in your cap), that could be a problem, as I plan to have a variable amount of enemies, and way more than 3.

    However, I did manage to get one type of object to be attached to the ship instance using an owner variable! Maybe we could make some kind of mix between both of your examples. I have tried this, but alas something is off. Here is my testing cap. Make the 'sTeam' object invisible to see the ship angles better. ;)

    And thanks again!

  • The answer is picking with the array.

    TA is still were the x. y. are stored

    But I also added a separate array for looping, It's just easier.

    and the "9999999" is just an arbitrary high number.

    For whatever reason you can't use an every (x) amout of time/tick and a "for each loop" so keep that in mind.

    https://www.dropbox.com/s/6vvyhcvfmx7ohd1/help.cap

  • Thank you for helping bartosh, but last night I finally got it working!

    <img src="https://dl.dropbox.com/u/21499454/events.png" border="0" />

    Using this, and also having tons of bullets being fired, I was able to get around 2000+ FPS!

    In this screenshot I had recreated the lines you had and zoomed out to see who was targetting who, which reduced the framerate a bit:

    <img src="https://dl.dropbox.com/u/21499454/framrate.png" border="0" />

    The targets update every 500ms, as I heard the 'Pick closest' was very CPU intensive, which is why it seems they aren't aiming at the closest enemy in the screenshot.

    Thank you so much for helping me get this work, and have an awesome day! :)

  • no problem, glad to help.

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