How do I Make my enemies chase the player with pathfinding.

Get help using Construct 2

Post » Thu Jan 12, 2017 5:24 pm

I got it, I will try to have a look at it later on. Hopefully you can find a solution early :-)
B
21
S
5
Posts: 52
Reputation: 1,308

Post » Fri Jan 13, 2017 1:56 am

Okay.. so I THINK I can explain your problem, but I don't know the solution off the top of my head.

In my examples, the pathfinding is not working how you want.

In your example, the pathfinding IS WORKING how you want.
However, collisions are not. I've seen people have this problem with bullet behaviour. I'll explain:

Let's say your solid object is 8 pixels wide. let's say a bullet heads toward that object with a speed of 20 px/tic..
This can result in the bullet jumping entirely over the solid, so no collision is actually registered.
I believe something similar is happening to your pathfinders. Maybe when they turn or something, they become close enough to the other side of the solid, that they end up there.

Honestly, I'm not completely positive on that.. (I could be completely wrong) but seeing as you don't seem to getting much help (rare around here), I figured I'd share my theory.. Hope it helps!
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Fri Jan 13, 2017 5:29 am

Thank you so much man for posting your theory, and exactly:

My .capx is WORKING as I want to, however, the collisions on the obstacle of the pathfinder are not.

Your .capx shows the pathfinding working but not how I want to (a continuosly chase it's what I need.)

Something that might be causing problem is the resolution and could fit with your teory, since I DID NOT have this problem back then when I created the same system in a 32 cell size. we're reworking the game to a simpler resolution and that ended up using tilesets 16x16, that indeed, need a pathfinding map of 16 cell size.

Wish I could just get help from @Ashley or @R0j0Hound, maybe they know how could I get a workaround for this!
B
9
S
2
G
2
Posts: 21
Reputation: 1,567

Post » Fri Jan 13, 2017 12:30 pm

This is actually an incredibly difficult problem. I would recommend not trying to handle collisions with the walls, because then you open a new can of worms where objects constantly get stuck.

The main problem is the rotate speed is relatively low compared to the acceleration and speed. So the enemies can only turn in very wide arcs, while chasing you down a narrow corridor with very tight turns and corners. The pathfinding behavior does try to slow down objects so they can make the turn, but I guess it doesn't work that well, and if it did, your enemies would spend most of their time going slowly to make sure they can make the tight turns. This would probably spoil the game as they would easily get left behind.

Basically if you set all of them to have a rotate speed of 3600 they follow the player just fine, but sticking to 45 degree angles. You probably just want to find the best rotate speed to compromise.
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Fri Jan 13, 2017 3:41 pm

@Ashley , thank you for answering and posting the solution.

Indeed, that was the problem! the rotation speed. since my enemies are fast, they needed a highger rotation that ended up solving the problem. or at least that's what I think and I'm seeing, you can look it by yourself at this .capx I made with the rotation fixed! so anyone who went into this problem could get this .capx and see that actually it has a solution:

https://www.dropbox.com/s/wlbd7ugm4tch5 ... .capx?dl=0

Also, I've implemented a LOS to see that you won't be actually seeing them rotating that fast because you could adjust it manually by setting rotating object to no in their pathfinding properties.

and in this gif I'm showing the fact that my guys are following properly now. :D!
Image

Thank you guys! you might want to pin this to the How do I FAQ. I didn't see something like this in that place.
B
9
S
2
G
2
Posts: 21
Reputation: 1,567

Post » Fri Jan 13, 2017 7:43 pm

oultrox1995 wrote:@Ashley , thank you for answering and posting the solution.

Indeed, that was the problem! the rotation speed. since my enemies are fast, they needed a highger rotation that ended up solving the problem. or at least that's what I think and I'm seeing, you can look it by yourself at this .capx I made with the rotation fixed! so anyone who went into this problem could get this .capx and see that actually it has a solution:

https://www.dropbox.com/s/wlbd7ugm4tch5 ... .capx?dl=0

Also, I've implemented a LOS to see that you won't be actually seeing them rotating that fast because you could adjust it manually by setting rotating object to no in their pathfinding properties.

and in this gif I'm showing the fact that my guys are following properly now. :D!
Image

Thank you guys! you might want to pin this to the How do I FAQ. I didn't see something like this in that place.

Looking at this latest gif a question came to me:
How can we handle the guys entering in each other?
B
20
S
4
Posts: 385
Reputation: 2,270

Post » Sat Jan 14, 2017 12:28 am

Zathan, I'm not quite sure, but different speeds (something like random max speed for making them slighty getting apart) or using boids plugin could do the job.

behavior-rex-boids_t126707

Dunno if someone has another workaround for that. I'm trying with different speeds and is doing a pretty decent job.

You might want to create a 'How Do I...?' post or look if someone solved that detail.

Here's a WIP (work in progress) gif using different speeds, isn't perfect but is quite a complicated problem you got there, I do suggest maybe with boids or looking around as I said! I might try boids later. Dunno if @Ashley got a word for your question.
Image
B
9
S
2
G
2
Posts: 21
Reputation: 1,567

Post » Sun Jan 15, 2017 1:12 pm

Crowd avoidance is another incredibly difficult problem with lots of nasty edge cases. But you can make a reasonable simple approximation. One example is to have a rule like: if two enemies are overlapping, pick the one further away from the player, and make them slow down. This means if enemies bump in to each other, the one behind waits to let the one in front ahead. It's not perfect though, especially if you end up with a large crowd, but it can help a lot with simple cases.
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Sun Jan 15, 2017 4:21 pm

Yea, something like I did but with a new condition of making them slow down will actually do the trick. thanks @Ashley for being such helpfull!
B
9
S
2
G
2
Posts: 21
Reputation: 1,567

Post » Sun Jan 15, 2017 9:24 pm

That's a hell of a topic :)
Thank you oultrox and ashley!
B
20
S
4
Posts: 385
Reputation: 2,270

Previous

Return to How do I....?

Who is online

Users browsing this forum: diamantico21, ratboy3, TRMG and 31 guests