- 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)
- 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)
- 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. -
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.