How do I prevent NPCs moving through Solids (Pathfinding)

0 favourites
  • 5 posts
From the Asset Store
Fantasy RPG Human-NPC assets pack of 15 characters
  • 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.

  • Bump

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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

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