How do I make a sprite with Pathfinding pick the closest object and then go to it?

0 favourites
  • 10 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.
  • The problem is that i can make the sprite pick the closest object, but can not make it make a path to it

  • Sprite is not moving
    Object pick nearest to Sprite.x, Sprite.y
    	Sprite find path to Object.x, Object.y
    
    Sprite on path found
    	Sprite move along path
    

    If you have multiple sprites, you might need to use "For Each" loop.

  • Thanks, but a new problem appeared, enemy flees to closest to it place, but it ignores "furthest to player" condition and just stays here

    Here is the code

  • Pick Nearest picks just one instance of EnemyFleePlace. So any other picking after that will not have any effect.

    If you want to find a place which is close to the enemy, but also furthest from the player, you need a slightly different approach. For example, you can use a second LineOfSight behavior to pick all places which are within a certain range from the enemy. And then pick among them the furthest from the player.

    Also, if you have many enemies, you should add "For each Enemy" to the top of this event.

  • Thank You! I have not tried it yet, but i definitely will!

  • Hi again!

    It partially works, but when enemy already reaches the "flee point" and player gets too close again, enemy just tries to go to the same point and stays at the same point, help! (i have multiple enemies, and that`s why there is a "for each" condition)

  • No, your screenshot has the same problem as before! When you are picking a nearest or furthest point, it picks only one point instance! And you can't pick any other point after that, because it will pick from the previously picked scope of one.

    Imagine you picked the biggest apple from a bowl. And then you try to pick the tastiest apple among the one you picked, but it's only one apple, so it makes no sense.

    You need to pick all points in enemy's LOS range - this will pick several instances. And then among these several instances pick the point which is furthest from the player.

    .

    Also, remove the second "every 0.2 seconds", it's not needed.

  • Ok, so i added a second LoS, and what do i do next? Also thanks for your help, I really appreciate it

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Something like this I suppose:

    For each Enemy
     Enemy has LOS2 to Place
     Place pick furthest to (Player.x,Player.y)
    
  • Maybe this can work?

    youtu.be/cf4fwgjAJK0

    Hope it helps

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