Pick closest - not self

Get help using Construct 2

Post » Mon Jan 23, 2012 10:28 pm

I have an enemy ship sprite and I want to set one of it's instance variables to be the closest enemy ship that isn't itself. If I use the "Pick Nearest to" condition it will always pick itself, which doesn't help me.

Any ideas on the easiest way to do this?

Thanks.
B
20
S
5
G
3
Posts: 65
Reputation: 3,764

Post » Mon Jan 23, 2012 10:59 pm

Without seeing the capx, a quick dirty trick would be to create a temp variable, set it to the enemy ship's UID and add a condition "Ship.UID /= tempVar".

After depending on how the capx is setted, there might be some more elegant solution.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Tue Jan 24, 2012 12:57 am

I made a little example capx that shows what I'm trying to accomplish.

http://dl.dropbox.com/u/28484936/pick_closest_problem.capx

The ship that is controlled by the mouse is a part of a family called "Family Enemy Ships". There are two types of ships in this family. I want to be able to set an instance variable for the mouse-controlled ship to which ever object from that family that it is closest to. Currently it always picks itself as being the closest.

Hope this helps explain my situation.

Thanks, Kyatric!
B
20
S
5
G
3
Posts: 65
Reputation: 3,764

Post » Tue Jan 24, 2012 1:33 am

Not sure if it will work, but you might try to filter the main ship out using an instance variable. But you would still need to reference the main ship's x,y, so you would need a couple other variables to store that.

Like:
sprite.variable("selected")=0 // main ship would be 1
sprite pick closest to globalx, globaly
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Jan 24, 2012 2:33 am

I made this

It's tricky/hacky.

I couldn't get what I wanted with "Pick Nearest", so I went the other way around.
Find the ship that has the smallest distance with the current mouse coordinates, making sure that we're not testing the ship which position is the mouse's position (our controlled ship).

So, it works...
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Tue Jan 24, 2012 6:12 am

If you use the index, its pretty easy to filter it.

pick enemy closest
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Jan 24, 2012 6:39 am

Oh darn, I don't have the indexing reflex yet.
Nice @Newt.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Tue Jan 24, 2012 8:27 am

Should be interesting:
closeDetection.capx
Last edited by Yann on Sun Sep 14, 2014 9:52 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jan 25, 2012 12:49 am

Thank you for the help, everyone. This was very informative.

Yann, I ultimately found your execution to be the most useful for my situation. Thank you so much for the time you put into that example project. The visual element really helped me to understand what was going on.

My game is coming along very nicely, so far, thanks to all the helpful people on this forum. I love you all!
B
20
S
5
G
3
Posts: 65
Reputation: 3,764


Return to How do I....?

Who is online

Users browsing this forum: Artpunk, DemantDigitalArt, Magistross and 31 guests