Hi everyone! Today i was training on script and i’ve tried to make a simple pathfinder to go on a seat choosing them randomly, the issue is that for some reasons the pathfinding overlaps with the seats making the npc go from all seats before reaching the one he should go
for example, the seat is N3, he goes over the 1,2, and then the N3
if is N4 he goes over the 3 and then the N4
From what I understand, you’re essentially having an error, where the ray-cast fires, but builds a path overlapping all the seats, is this correct? And you want the ray-cast to lead you to the seat its raycasting to, but for some odd reason, it’s building around all the seats combined.
Here are some solutions that come to mind if I was experiencing this:
1.) Perhaps you don’t need to ray-cast to the seat. If there are no obstacles, instead… why not use something like MoveTo()? And if there IS something, why not just ray-cast from the characters point relative to the part it needs go to? That way, if there is a part, then instead ray-cast.
2.) This can be tied into solution #1. Make the NPC jump until it’s in the seat its ray-casting to, so maybe make an attribute listing what part it’s going to, and when it sits, compare if that seat is equal to the part its pathfinding to, and jump if its not the seat it’s going to. (Make sure it’s an Object Value, that way the names don’t particularly matter / you don’t need to insert any unnecessary values classifying them. )
If you do plan on using solution 1, I’d also look into the dot product to compare two different directions of unit vectors. (Basically, making FOV! A range in which we would compare when figuring out if we should raycast, so if object is in sight, and there are no parts in front of it, then you don’t need to raycast, else if there is a part in front of it and it’s in the fov / not, then raycast!)
Nvm i’ve readed the answer wrong, Aldo i’ve found a solution, for some reason instead of waypoint loop if changed to MoveTo only (it was in the code before but was Looped to see the dots) the path fixes