How to move npcs without them rushing into each others

so im trying to make 2 systems one is “formation system” and the other is “following system” for my warlord like game and i used moveto for the following part but the npcs kept rushing into each other

1 Like

Funnily enough I actually just finished making something like this.

Have you ever heard of Boids? If so it might be what you are looking for.
I highly recommend you learn how to do this in 2D like I did. I learnt it back a couple years ago coding some JS in khan acad.
If you search the internet there are countless tutorials about it. Here’s one that gave me the idea.

2 Likes

To move NPCs without collisions, use pathfinding algorithms and obstacle avoidance techniques. Also, apply separation behavior to maintain safe distances between NPCs.

somehow i was able to make a line formation + square formation by this method which i know is not the best but it works and i will apply some pathfinding to it to make it smooth

	elseif action == "Line" then -- if the action was line formation
		
		for index = 1, #selected do -- for every selected unit in the table do
			local object = game.Workspace.selected:FindFirstChild(selected[index]) -- the unit selected

			object.Humanoid:MoveTo(mousepos.Position + Vector3.new(-5,0,index*5)) -- some weird math

		end

1 Like

i tried using steering behavior but it is so advanced at my level i was able to keep it simple with this post

Well, honestly I think it is worth a look at. I have done some work on this years ago and I used method similar to

One of the issues with this is that each unit is assigned to its “index”.
I use to play bot commander and the main problem is that if you rotate since the NPC always find the straightest path it end up looking very rigid.

I highly recommend you look into steering behaviours. They are not as difficult as long as you know the way in which it can form a formation.

well badly i don’t know how to use module scripts and i need module scripts to make it looks clean and in the steering behavior fourm the used module scripts which i didn’t get used to

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