Optimizing AI Help

Hello fellow developers! I am making this post to find out how I should optimize an AI system that I am thinking about making. Basically, how should I handle the pathfinding so that it replicated to the server and it is very smooth, meaning it is ran on the client

I would appreciate an explanation on why I should do these things, as I want to learn. I have looked into a few tutorials, but they are all 1 hour plus and I don’t have that kind of time

Thankyou!

5 Likes

Also, if you could give some insight on how I should go about making the ai animate while they are walking - if not that’s ok too. Thanks in advance

1 Like

If the “AI” is a humanoid with ROBLOX animations attached, you can simply use the humanoid class method:

MoveTo(waypoint: Vector3)

If you are planning on building your own waypoint system, the combined use of waypoint data caching for AI learning, and using MoveTo in conjunction with Raycasting for obstructions.

I will be using pathfinding.

What I meant by “optimizing” is how should I replicate it to the client, so that it doesn’t appear laggy on the client, but the server still knows where it is?

Pathfinding on the server always replicates to the client?

I understand that, but how do I make it not laggy

It’s not preferred but you could root the Pathfinding execution to the client and then constantly inform the server of the adjusted world CFrame where the server would adjust it; probably via RunService.Stepped?

It’s not something I would do however if you are experiencing replication lag from Pathfinding, I would opt to writing a custom pathfinding class, using the MoveTo(...) method. :person_shrugging:

How would you suggest I make the custom pathfinding? (I am assuming with a bunch of nodes), and also how would I incorporate things such as moving around a wall?

As I said in my earlier reply, using a combination of raycasting for obstacles and possible routes is the best route for such. You would continuously raycast for potential obstacles, and if one is obstructed, you would raycast for a go-around route.

You can then incorporate learning for previous routes in the world space CFrame, for example the AI would remember previous routes based on the world CFrame the waypoint has landed them at, and instead of conducting more raycasting, the AI would utilise stored data to make a responsible pathing decision.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.