Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make NPCs not collide with each other? (Unsolved)

As of now, I'm making a game where NPC's will have to only take one path, and I need for them to be able to walk through each other. I have already solved the following issues --

  • I put a BodyGyro and BodyPosition to keep them in place, while the floor is CanCollide = false.
  • All of the NPC's body parts are CanCollide = false

An issue came up to where whenever the NPC moved (for instance, with manually setting the MoveTo property of Humanoid), the Torso and Head would become CanCollide = true. To solve this, I put the following script into the head (it's inefficient, but it was for the sake of testing) --

while true do
	script.Parent.CanCollide = false
	script.Parent.Parent.Torso.CanCollide = false
	wait()
end

This did work, making the torso and head always stay CanCollide = false. However, it still didn't work. Whenever I make an NPC MoveTo a position behind the other (which was a complete duplicate), it will still get caught on the other NPC about 95% of the time.

Whenever the NPC is moving, I can see the CanCollide property flash extremely quickly (as I would expect). Does this mean a shorter wait time would rectify the situation?

Or, is there another way to solve this issue (or another way to deal with NPC collision)?

Thanks for reading, and I hope to find out a bit more on this strange issue.

2 comments

1

Try using game:GetService("RunService").RenderStepped:wait() for the wait. Make sure it's a local script.

0

Sadly, that's not working out. Since this isn't a player-run character, local scripts aren't running correctly.

1 answer

Use the Changed event of the Head and torso and set the CanCollide to false in there. Voila.

1 comment

0

I'd have bet money that this would have worked, but sadly, it's still not changing things fast enough. I'm only using the Changed event, without any waits.

This discussion is preserved as it was. New answers, comments, and votes are closed.