How do I prevent NPCs moving through Solids (Pathfinding)

Get help using Construct 2

Post » Tue Sep 08, 2015 11:39 pm

Hey guys,

The NPCs in my game will attempt to Pathfind around a solid object, but if the Solid object rotates too quickly it sometimes collides with the NPCs. How would I make the NPCs react to this collision by being pushed back - and then shortly after have them resume their pathfinding.

Thanks.
B
64
S
21
G
7
Posts: 74
Reputation: 7,477

Post » Wed Sep 09, 2015 3:53 am

Bump
B
64
S
21
G
7
Posts: 74
Reputation: 7,477

Post » Wed Sep 09, 2015 1:09 pm

You have to improve the AI.
One thing you can do is add an invisible colider that always has its position set to an image point in front of the NPC. (This can be done by making a new sprite just fill in the square with any color and then hit okay. Set the viability to invisible).
Next go to your NPC and add another Image point and set it a bit infront of the direction that the NPC is facing.
In your code say;
--Everytick // "WhateverYouNamedCollider" | Set position to "TheNPCYouAreFixing" (Image point 1)

Now you just need to program the colider to check if it is overlapping something else that the NPC shouldn't and then tell the NPC to turn a different direction.

Another alternative is to have the solid object cause the NPC's x or y position to change based on its location to the solid object.
For example :
--IF NPC.x < object.x // Npc.x = npc.x -1
--IF NPC is overlapping Object

--IF NPC.x > object.x // Npc.x = npc.x +1
--IF NPC is overlapping Object
B
5
S
1
Posts: 24
Reputation: 650

Post » Wed Sep 09, 2015 7:03 pm

Another thing you can do(I will hopefuly make a tutorial for this), which is something I'm trying to do right now, is to only use the pathfinding behaviour for finding a path from point A and point B, and, instead of moving your object using the pathfinding, you can try and use 8 Direction as it has built in collision checks, and will collide with solids properly.
Banned User
B
6
S
3
Posts: 105
Reputation: 1,170

Post » Wed Sep 09, 2015 11:39 pm

tarik00555 wrote:Another thing you can do(I will hopefuly make a tutorial for this), which is something I'm trying to do right now, is to only use the pathfinding behaviour for finding a path from point A and point B, and, instead of moving your object using the pathfinding, you can try and use 8 Direction as it has built in collision checks, and will collide with solids properly.


@tarik00555, another member named @zatyka has already done something like this but with the bullet behavior (so maybe this will help): pathfinding-experiences_t81496
Direct Link: https://dl.dropboxusercontent.com/u/475 ... ement.capx
B
64
S
21
G
7
Posts: 74
Reputation: 7,477


Return to How do I....?

Who is online

Users browsing this forum: David181 and 15 guests