Pick closest - not self

0 favourites
  • 9 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • 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.

  • 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.

  • 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!

  • 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

  • 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...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you use the index, its pretty easy to filter it.

    pick enemy closest

  • Oh darn, I don't have the indexing reflex yet.

    Nice

  • Should be interesting:

    closeDetection.capx

  • 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!

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