"Pick nearest to" together with distance limitation

0 favourites
  • 9 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Guys, I'm newbie and I have a problem that I can not solve yet. Please see attached img to get understand my issue.

    I have a Family of objects - different boxes. I need to find the box nearest to the ship, but I have to take into account only those boxes that are at the fixed distance to the player.

    I can easily find the nearest box without taking into account the distance to the player by Pick nearest to target.X, target.Y. But there is a problem with linking it to the distance to the player.

    Perhaps I need to make an array of boxes that are at the desired distance to the player and then run through this array to compare the distance from each box to the target to find the closest one?

    How to implement this algorithm?

  • Use the Line of Sight behavior

    Player has los to box

    ->box pick closest to ship

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Use the Line of Sight behavior

    Player has los to box

    ->box pick closest to ship

    Set LOS to 200 px and excluded Solids from obstacles.

    Smth is wrong with the distance but in general looks like it's working.

  • Line of sight is for picking instances in front of other objects, and picking instances by means other than the system distance() expression.

    You may need to adjust the Los default settings however.

  • Line of sight is for picking instances in front of other objects, and picking instances by means other than the system distance() expression.

    You may need to adjust the Los default settings however.

    I updated my post, please check it once again.

  • Check your range.

  • Guys, I'm newbie and I have a problem that I can not solve yet. Please see attached img to get understand my issue.

    I have a Family of objects - different boxes. I need to find the box nearest to the ship, but I have to take into account only those boxes that are at the fixed distance to the player.

    I can easily find the nearest box without taking into account the distance to the player by Pick nearest to target.X, target.Y. But there is a problem with linking it to the distance to the player.

    Perhaps I need to make an array of boxes that are at the desired distance to the player and then run through this array to compare the distance from each box to the target to find the closest one?

    How to implement this algorithm?

    Hi

    You can use distance() to get the boxes in your radius, then pick the nearest one to the ship.

    http://www.sizzle-games.com/boxexample.c3p

    I Have attached an example .C3P file

    Just move the Player around (Arrow Keys)to try out the distance from players radius to the box, this is set at 200, but can be changed to anything.

    Edit, added drop and drag to boxes and spaceship

  • Take a look at the turret behavior beginner example in C3 and predictive aim example, they are using turret and all you have to do on turret is set the parameter property that says first in range to nearest.

  • Check your range.

    Sorry man, a stupid mistake - I considered a circle with 200 px radius the same as a 200 px distance from player. Draw a 400 px circle and your solution worked perfectly!

    You can use distance() to get the boxes in your radius, then pick the nearest one to the ship.

    Wow! So simple! Thanks a lot, sizcoz! I tried smth like this myself but didn't use Pick by comparison condition.

    My final code looks like this (I used your first version as a blueprint):

    gamecorpstudio, thanks a lot for great examples, I will definitely look through them!

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