How do I pathfind to near player

0 favourites
  • 6 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hi,

    I've spent the last few days working on a wee game, its going pretty well but I've hit a snag. I can get my enemies to go to the player using pathfind/line of sight, but they always end up at the middle of my player. Which is an issue for my combat which is done by selecting the enemy.

    I can get them to go to just off my character by pathfinding to Player.X-50 but that still means they all end up in the one spot.

    How can i make them fan out around me, I'm thinking some sort of pathfind to random angle. But I just don't know enough to implement it.

    Heres the code block Im focused on:

    Thanks for any and all help!

  • Just a wee bump, still stuck on this. I even took a break to implement a combat system, came back and no luck.

    My poor brain just isn't up to it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Anyone have any ideas?

  • Still hoping for some help

  • This is something that was shared with me here.

    newX = enemyUnit.X + cos(random(360)) * random(100)

    newY enemyUnit.Y + sin(random(360)) * random(100)

    Say your enemy was picking a random point within a 100px radius from itself to move to. This is how you would do that... so maybe..

    newX = playerUnit.X + cos(random(360)) * random(100)

    newY playerUnit.Y + sin(random(360)) * random(100)

    would pick a random point up to this many px from the player..... You might have to play with the numbers though. This could put the enemy 1px away or 100px... you would adjust your range like random(50, 100).. Then they would pick a random point from 50 to 100 px away..

    You'll have to use another method if you want these points to be specific... not sure about that kind of math. Also you would have to implement a feature if you wanted the enemies to pick random points around the player that weren't the same... like test all previous checks in a while loop and pick a new location until they aren't the same..

    Not sure if this is a better way or not... One thing I do know. If you want your points to be picked cinematically this will not work.

  • Hey man appreciate that! Definitely a place to start, will have a play and see what I find.

    Will post results here.

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