Enemies targeting each other

For questions about using Classic.

Post » Sun Sep 16, 2012 3:09 pm

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!
B
26
S
7
G
5
Posts: 202
Reputation: 5,235

Post » Wed Sep 26, 2012 9:35 pm

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.
B
6
S
2
G
5
Posts: 249
Reputation: 2,323

Post » Thu Sep 27, 2012 3:23 am

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!

(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 )Jayjay2012-09-28 00:27:25
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Thu Sep 27, 2012 5:05 pm

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".
B
6
S
2
G
5
Posts: 249
Reputation: 2,323

Post » Fri Sep 28, 2012 10:07 pm

[QUOTE=Jayjay] *post* [/QUOTE]

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.

[QUOTE=Bartosh] *post* [/QUOTE]

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!Phobos0022012-09-28 22:07:44
B
26
S
7
G
5
Posts: 202
Reputation: 5,235

Post » Sat Sep 29, 2012 5:06 am

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.capBartosh2012-09-29 07:07:07
B
6
S
2
G
5
Posts: 249
Reputation: 2,323

Post » Sat Sep 29, 2012 2:49 pm

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



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:



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! :)
B
26
S
7
G
5
Posts: 202
Reputation: 5,235

Post » Sat Sep 29, 2012 3:10 pm

no problem, glad to help.
B
6
S
2
G
5
Posts: 249
Reputation: 2,323


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests