Hey, so I’m currently trying to check if a the path from A to B is clear with Ray-casting, however, I faced a problem.
As you might already know, the ray doesn’t have thickness, meanwhile the mob that follows the path does. So sometimes if the path is slim, it will still be seen as clear while it isn’t due to the path not being thick enough.
So that raises the question, is there a way to Ray-cast from A to B, whilst having it check for thickness?
Note that the path is in a terrain which have parts on it.
I’m sorry, but I can’t really understand what you’re trying to raycast onto.
Are you checking for a mob to intersect with the ray?
I’m trying to check if the path from A to B is clear and can have the mob move in it, but since the mob has thickness/is wide, sometimes the raycast would say it’s clear even though its not.
In this case, I think it might work better for you if you use two rays.
Here’s how and why:
Instantiate two rays. One starting at the very left of the mob’s model, and the other starting at the very right.
Cast them forward in whatever direction the mob is traveling and check if both rays return nil.
If either one ray returns a hit, this would mean the path is too narrow to move through.
Hope this helps!
Yeah have been testing and have came up with this, just tested it.
local Way1 = Ray.new(Start + Vector.RightVector*Radius, (Vector.LookVector+Vector.RightVector*Radius) * (Start-End).magnitude)
local Way2 = Ray.new(Start + Vector.RightVector*-Radius, (Vector.LookVector+Vector.RightVector*-Radius) * (Start-End).magnitude)
local Blocked1 = workspace:FindPartOnRayWithIgnoreList(Way1, Ignored, false, true)
local Blocked2 = workspace:FindPartOnRayWithIgnoreList(Way2, Ignored, false, true)
if not (Blocked1 or Blocked2) and Start.Y - End.Y < 1.5 then
You might also want to cast some rays downward along the path, although this is specific to your map.
e.g. by just casting a ray, your AI would think that there is a direct path from on top of one roof to on top of the other (since there would be no obstruction), but this isn’t the case because it would fall down. I do this by casting straight downwards 5 studs from several points along the ray, and returning a ‘blocked path’ if there is no hit part (i.e. indicating a fall).
That’s presumably handled by the pathfinding. His issue was that the pathfinding assumes you are a micrometer thick.
Pathfinding should already check for thickness, look at the arguments for CreatePath. I don’t think OP said anything about the pathfinding service though, just raycasting between 2 points
True, but I was making a simplify script, where the waypoints are simplified to only those necessary.
Thus, sometimes a point was placed next to another, however it was required to move to point1 before the required point, so I was reaycasting with thickness from each point to another to avoid that problem.
That is actually a really interesting idea. It’s a little annoying how many unnecessary waypoints there are
My pathfinding system for zombie AI works like this–
go through all player characters, sorted in ascending order according to distance from the zombie, so closer players are checked first.
check if a direct ray can be cast to the player, (with sanity checks), to reduce computational overhead in calculating paths. If so, walk to the player (update position every 0.3s). If not, computate a path; if no successful path is found, move on to the next player; otherwise, follow the path.
every 5 waypoints reached, re-calculate the nearest player; if it’s a different player, repeat initial following logic for them (either waypoint or direct MoveTo). If it’s the same player, check if there’s a direct ray; if not, only update the path if the player’s position has changed by a magnitude of >20 studs.
Feel free to PM if you have any pathfinding or AI questions. I’m by no means an expert, but I’ve spent the past few days trying to figure my way around pathfinding service and effective, efficient AI so the pains are fresh in my head
That’s the exact purpose.
Almost the same way I’m doing it. However I recalculate the waypoints more often, since a player slight change can cause alot of changes. Certainly will change the refreshing speed once all the systems are linked together to find the sweet spot.