Simple pathfinding issues

0 favourites
  • 3 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I want to be able to set up some waypoints in my project so when it's ran the enemies seem to wander the map to each of the waypoints so I can control where they can and can't go on the map.

    But, I also want them to look as though they are wandering randomly around the map. They can change direction, but I only want them to be able to travel to the nearest waypoint.

    Is there anyone that's had experience with this?

    I've been using the pathfinding example included with construct 2, and while it's absolutely awesome, I can't really seem to get it to work with what I need currently.

    Thanks guys!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've created my wandering NPC's in my zelda game by creating a sprite object called "pathsprite" and in each frame have images for the avialable directions (make sure you set the speed to 0 so it does not animate) for example:

    frame 0 would have a image of an arrow pointing to the left

    frame 1 would have a image of an arrow pointing to the right

    frame 2 would have a image of an arrow pointing up

    frame 3 would have a image of an arrow pointing down

    frame 4 would have a image of an arrow pointing up,down,left and right

    frame 5 would have a image of an arrow pointing to up and right

    do this for all possible directions you require then set up logic like this

    If player overlaps pathsprite and frame = 0 then set "NPC" movement direction to 180

    If player overlaps pathsprite and frame = 1 then set "NPC" movement direction to 0

    If player overlaps pathsprite and frame = 4 then set "NPC" movement direction to choose(0,90,180,270)

    Also do a check position for when the NPC is (say) 4 pixels or less in distance then set NPC to the position to the pathsprite its overlapping. This ensures it goes throught the center of all pathsprites, you could also have the NPC wait at various places with a random timer to give the impression the npc is thinking were to go.

    Hope that maks sence im at work so unable to provide screen shots.

  • No, that definitely makes sense! Thanks a lot!

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