How to collide non-collidable parts?

  1. What do you want to achieve? Keep it simple and clear!

I want the enemies (those Bloons) to collide with themselves.

They are normal parts with a billboard gui and no script inside. Instead, they are “controlled” with a server script inside ServerScriptService. (to make it easier to modify)

  1. What is the issue? Include screenshots / videos if possible!

The enemies keep grouping up in one place. I can’t see how many there are if they are packed up (see below)

This is the video. As you can see, the bloons are grouping up. I want them to collide with themselves.
robloxapp-20230628-1848271.wmv (2.1 MB)

The bloons are anchored, with CanCollide set to false. If I unanchor them, they go super crazy and start going everywhere the second they touch another bloon.
Also, they are moving with this script :

function moveForward(bloon, name, distance)--makes it move forward, no problem with that
	if bloon.Name == name then
		bloon.CFrame = bloon.CFrame * CFrame.new(0, 0, distance * -1)
	end
end
--below, turns to the nearest player (part of the script, works fine)
bloon.CFrame = CFrame.lookAt(bloon.CFrame.Position, humanoidRootPart.CFrame.Position)
--function from above, moves well
moveForward(bloon, "Red", .1)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Here are the solutions I tried

  • Collision Groups
    I tried making a collision group for the bloons. Unfortunatly, this wielded no result, since the bloons are anchored. :slightly_frowning_face:

  • Not moving if touching another bloon.
    Here is the code I used for this method :

local boolTouchingBloon = true
while task.wait(0) do

	for i, bloon in pairs(bloonsFolder:GetChildren()) do
-- some stuff, full final script at the end of this post
		for x, touchingParts in pairs(bloon:GetTouchingParts()) do
print("CheckingParts")--gets all bloon's touching parts
			if touchingParts.Parent == bloonsFolder then
print("Oh!Touching!")
				boolTouchingBloon = true--makes this variable true if its touching

			end

		end

		if not boolTouchingBloon then-- only moves if NOT touched
--explained earlier in this post
			bloon.CFrame = CFrame.lookAt(bloon.CFrame.Position, humanoidRootPart.CFrame.Position)

			moveForward(bloon, "Red", .1)

		end		

	end

end

Unfortunately, it doesn’t stop any bloon. Although, it prints (“Oh!Touching!”) occasionally. I you can see it in the video earlier in this post.

I tried removing the “not” in “if not boolTouchingBloon then…”, but the bloons wouldn’t move at all.

  • Making it move away from the touched bloon

Again, this did not have the expected results. The touched bloons would rotate with themselves instead of going away.

I deleted this script’s version and I do not have it anymore though. I searched through the script recovery, but nothing.

I tried to make it move back until it doesn’t touch any bloons, but it wouldn’t work in theory. I hope this drawing can clarify what I mean :

I hope this can help you though.

Full script in case you need it :

wait(2)

local bloonsFolder = workspace.Bloons




function moveForward(bloon, name, distance)

	if bloon.Name == name then


		bloon.CFrame = bloon.CFrame * CFrame.new(0, 0, distance * -1)


	end

end

bloonsFolder.ChildAdded:Connect(function(addedPart)

	addedPart.Touched:Connect(function() end)

end)
local boolTouchingBloon = true
while task.wait(0) do

	for i, bloon in pairs(bloonsFolder:GetChildren()) do

		local players = game.Players:GetPlayers()
		local distance = 2 ^ 31 - 1
		local distanceChosenPlayer

		for v, forPlayers in pairs(players) do

			if forPlayers.Character then

				local distanceFromPlayer = forPlayers:DistanceFromCharacter(bloon.CFrame.Position)

				if distance > distanceFromPlayer then

					distance = distanceFromPlayer
					distanceChosenPlayer = forPlayers

				end

			end
		end

		local character = distanceChosenPlayer.Character
		local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")

		bloon.CFrame = bloon.CFrame - Vector3.new(0, bloon.CFrame.Position.Y, 0)

		boolTouchingBloon = false

		for x, touchingParts in pairs(bloon:GetTouchingParts()) do
print("CheckingParts")
			if touchingParts.Parent == bloonsFolder then
print("Oh!Touching!")
				boolTouchingBloon = true

			end

		end

		if not boolTouchingBloon then

			bloon.CFrame = CFrame.lookAt(bloon.CFrame.Position, humanoidRootPart.CFrame.Position)

			moveForward(bloon, "Red", .1)

		end		


		bloon.CFrame = bloon.CFrame + Vector3.new(0, 4, 0)

	end

end

Is there a mechanic am missing? Or should I unanchor the bloons? I don’t know.
Thank you for listening to me, any help is appreciated!

This is my first post. I searched on the forums and on Google, but didn’t find what I wanted.

Collision Filtering | Documentation - Roblox Creator Hub

Thanks for the response.
I already checked the documentation page, but this wasn’t what I was looking for.
Have you read all my post? I said in it that they were unanchored. Collision filtering isn’t very useful in that case.

Also, I’d like to mention that the bloons are moved by changing its CFrame, not forces or anything like that. That’s why I can’t unanchor it.

Of course, if you read all my post, you would have known :confused:

Thank you for trying tho, I guess.

If you’re willing to compromise on performance, you should try using BodyVelocity on the bloons rather than changing their CFrame directly, which would mean they would need to be unanchored. A more performant solution would be to implement custom 2D collisions which isn’t the easiest thing to do.

Thanks for the response.

I like the ideas you said. I knew there was something like velocity or forces, but didn’t know the exact name of it.

Although, body velocity wouldn’t be a good solution in my opinion, because there are many bloons. You said it was not for performance, so I’ll skip on that.

I’ll look 2D collisions on the documentation page. Thank you for helping me and for solving my issue! And for reading all my post :eyes:

1 Like

Please mark his post as the solution if it worked for you

1 Like

Hello again, here’s a quick update on my situation.

I can confirm that the bloons are going apart correctly! Here’s my solution :

Instead of one main script interacting with every bloon, now every enemy has a script. It also makes it way easier, since there are less for loops! I found out that GetTouchingParts() is working correctly. Here’s what happens now :

bloonCollide

I don’t think its performant, but I’ll take what I can get.

Although I didn’t choose Azur’s way, I think it made me “brighten” up to see more solutions.

Should I give him the solution mark or no? He did help me, but not in the expected way.

Thank you again for your time, have a fantastic day!