How do I pathfind to near player

Get help using Construct 2

Post » Sat Aug 29, 2015 11:17 pm

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:
Image

Thanks for any and all help!
Last edited by KeeghanM on Tue Sep 01, 2015 10:31 pm, edited 1 time in total.
Image
Keeghan McGarry | Managing Director
Facebook-Website
B
14
S
3
Posts: 77
Reputation: 1,081

Post » Mon Aug 31, 2015 3:58 am

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.
Image
Keeghan McGarry | Managing Director
Facebook-Website
B
14
S
3
Posts: 77
Reputation: 1,081

Post » Tue Sep 01, 2015 10:31 pm

Anyone have any ideas?
Image
Keeghan McGarry | Managing Director
Facebook-Website
B
14
S
3
Posts: 77
Reputation: 1,081

Post » Fri Sep 04, 2015 11:36 pm

Still hoping for some help
Image
Keeghan McGarry | Managing Director
Facebook-Website
B
14
S
3
Posts: 77
Reputation: 1,081

Post » Sat Sep 05, 2015 12:15 am

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.
B
7
S
2
Posts: 92
Reputation: 663

Post » Sat Sep 05, 2015 1:11 am

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

Will post results here.
Image
Keeghan McGarry | Managing Director
Facebook-Website
B
14
S
3
Posts: 77
Reputation: 1,081


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests