Optimized A-STAR(A*) Pathfinding

I want to thank @Artzified for his tutorial and @tracedrounds that helped me a lot there, thanks to them i managed to create a somewhat stable Optimized A* pathfinding algorithm.

I am so happy to announce that i am open sourcing my pathfinding code for everyone.
Here is the place for testing
TestAStar.rbxl (79.0 KB)

(Please if you find any bugs or Any improvements post them here below)

In the next Episode i will try to make An a* pathfinding algorithm based on @tracedrounds code. if i get time
here is a video to demonstrate:
robloxapp-20240731-1251031.wmv (700.4 KB)

10 Likes

Any videos, benchmarks, ANYTHING???

Also does it even support 3d movement or just 2d???

3 Likes

Good work bro real cool Pathfinding algorithm :goat:

4 Likes

It supports 3d(flying) but you have to code the flying agent yourself.

Also feedback on how to optimize it further or any bugs found would be appreciated

No videos because i am a bit lazy to upload. Sorry

That’s also not really that good then, 3d flying is unoptimized. You need to make up a better way to do so.

Well thats not a really responsible way to upload a resource.

3 Likes

That comment doesnt help at all. saying “3d flying is unoptimized” doesnt help much. Adding 2 more nodes for +vector3.YAxist and -Vector3.Yaxis is not any different than adding 2 nodes in the X or Z scale. Also you are not helping.

If you cant help, please refrain from adding more comments here.

Also i will upload a video

1 Like

I am not even trying to help you.

I’ll explain now because you seem a bit new.

Why adding two nodes on y axis cause lag?

Let’s say your algorithm searches an area 10x10 studs, that’s 100 studs scanned, seem pretty good. Scanning an additional axis would mean 1000 studs and doing this on a larger scale could be devastating. Especially if there are multiple obstacles. This would mean too much lag on computing. Rather, take my approach of using raycasts to see if the next node is above our initial height and then set our height to that specified height which is much more optimised and that’s what I did for my algorithm.

Also you’re suppose to upload an mp4 file for a better preview as well as benchmark results on how much optimised this is.

take my approach of using raycasts to see if the next node is above our initial height

Elaborate on that? You dont need raycast to check if the next node is higher than the initial node. You can check the Y coordinates for that also Workspace:getPartBoundsInRadius is sort of raycasting to check if the point is inside a map block

Regarding the 3dgrid. I am using a dynamic(No premade node) pathfinding that is based on directions only. Seems like you havent opened the project to check the code.

True, but that’s one way. I cannot explain or show my code due to being on phone which is the answer to your second argument. I am on phone.

Didn’t check the resource but for your comment;

Guys you do not need 3d movement. You only need to move the npc 2d based on ground below while checking front and up directions for collisions and adjusting flight height with it. Yes it will rarely take longer paths but you are saving a lot of frames.

Could you show us example? I think raycast from the next node’s X and Z to calculate the height would be better like that?

That’s true but most games usually have some depth to them as well. It could be good for some games but for most you need some y axis implementation that is optimised.

Yes, exactly like that. That’s how I managed to do it.

When you get back to Desktop could you show us some examples?

Ive read a lot that raycasts in ROBLOX are unoptimized by themselves and they should be used as last resort and not every tick

When i was testing the roblox studio place, the script got timeout. And then the NPC would not move anymore.

Maybe. I am currently on vacation but just giving a basic idea is that you need to cast a ray 7 studs or move above from your presummed next point downwords to about 20 studs and also cast rays from the point where the topray impacted a part to see if there is sufficient space. Also use workspace:GetPartsInRadius to see if that point is actually traversible or not. Or just use raycasts.

Basically:

parentNode -- our parent node
local nodePosition = -- our nodes position

local heightRay = Raycast(nodePosition+Vector3.yAxis*10-Vector3.yAxis*20)

if heightRay then
local upCheckRay = Raycast(heightRay.Position,Vector3.yAxis*7)
local collissionRay = Raycast(parentNode.Position+Vector3.yAxis*7,direction) -- where direction is basically where the new node would be.
if not upCheckRay and not collissionRay then
--make your point
end
end

Yep, sometimes it happens and i dont know why. I have been looking for help about the timeout for 2 months now. I cant seem to trace the issue sadly. That is why i seek for help as well.

Yes, i understand the concept. thanks. On my time i will upgrade the code and post the code here. Thank you.

Great. Glad I could help you in this!