Pathfinding waypoint-to-waypoint raycasting isn't working, need alternatives

Recently I’ve been trying to make a pathfinding script, and I succeeded, however, I’ve discovered a problem.

Screen Shot 2020-11-12 at 3.39.11 PM

The generated path can’t detect for walls blocking it. So, I tried to see if a ray could reach the point if so, then use that point. So far, this is not working at all I’ve been trying to fix this since ysterday. I’ve abandoned my attempt to use raycasting as it would only crash my studio upon running. Any ideas on how to do this?

1 Like

What part of your script is not working? If its the rays make sure that the ray is long enough to reach the position of the waypoint. It would also help if we saw the code your working with for reference. Hope this helps.

I’m not sure if you would want to go with this as it does not adapt to changes in the map however you could build the map and use a system like this.

You would place the waypoints around the obstacles in your map and they would represent the places your NPC could move to.

The image below is an example of such a system.

Node     Connections
1        2
2        1,3,4
3        2
4        2,5,7
5        4,6
6        5
7        4,8
8        7,9
9        8,10
10       9

NOTE: Waypoints are usually easy to set up however they don’t result in very realistic movement paths

You could then build a table showing which ones connect to each other like the one above and move the NPC by using some kind of searching algorithm of your choice.

You could also divide the map up into a grid and mark blocked sections of the map. You could then use the A* algorithm to search through this or yet again any algorithm of your choice.

This is more like your current solution however this method stores the data about obstacles rather than detecting them in real time.

Hope this helps :slightly_smiling_face:

1 Like

I’ve got the same problem as well, but the best alternative that I found by myself is to use a RunService loop and just call a function that creates a new path and re-ComputeAsync() it. It will create a new path constantly and create new waypoints. Hope this help.

I found the problem, I wasn’t raycasting properly, thank you, everyone, for your help