How do I target a condition towards the nearest Sprite to another Sprite?

0 favourites
  • 5 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Hi there,

    We are using a simple pathfinding Line of Sight technique with a single line (Line of Sight Bar) that is directed towards the player at all times. If this bar is overlapping the player then the enemy can see you. Pretty simple.

    The problem I'm having is that if we have two enemies on the screen, we have two Line of Sight Bars.

    If the Line of Sight Bar is overlapping the Player, how do I choose the Enemy Object that is closest to the Line of Sight Bar's position?

    Note, the Line of Sight Bar has it's X and Y at the bottom left so we can resize if it needed. So the X and Y of the Line of Sight Bar will always be overlapping the enemy it is attached to.

  • Why are you using a line-of-sight bar sprite, and not Line Of Sight behavior?

    If you configure the LoS behavior, you can simply do:

    Enemy has LoS to Player
    Enemy pick nearest to Player.x, Player.y
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for replying dop2000,

    When testing this with the LoS Behaviour, we found it problematic and intensive when doing this on multiple enemies. This option was suggested from an old Construct 2 tutorial.

    I've just tried your method out, and for some unexplainable reason the Pathfinding does not move the Enemy until we've collided the player into a solid object.

  • With the LOS bar sprite, you should still be able to simply pick the nearest enemy to the player. Is the bar in the same container with the enemy? Then you can do "Bar is overlapping Player, Enemy pick nearest".

    I can't tell what the problem might be with the pathfinding without seeing your project file.

  • Fantastic, that's sorted it ... I believe I was being an idiot!

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