I’m making a randomly generated cart ride game and I don’t want two track pieces intersecting. I’ve already got the randomly generated part down, but now I need to know how to make sure two different tracks don’t collide. How do I do this?
Try WorldRoot:GetPartsInPart()
You could try using ray cast to check if there is a part infront or using region3. I think using touched would be pretty impractical since you’d have to create the track, use touch, then delete if it is touching.
You’d only need overlaps params to help you with this. Raycast would be too inefficient unless you want it to detect from the front and back only.
I have tried to use OverlapParams plus recursive funcrions to try and dix the issue. However, it was slow and horribly iniefficient. Do you have any code snippits for me maybe?
It worked me good, how was it inefficient and slow?
What do you want to do exactly that the Cart should not collide with another Card?
Sorry, I was on my phone earlier. This is my code:
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
function choosePiece()
print("Choosing Piece...")
local pieceIsFine = true
local chosen:Model = trackPieces[math.random(1,#trackPieces)]:Clone()
chosen:PivotTo(lastEnd.CFrame)
overlapParams.FilterDescendantsInstances = {chosen}
for i,v in pairs(chosen:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Start" and v.Name ~= "End" then
local partsIn = workspace:GetPartsInPart(v,overlapParams)
if #partsIn > 0 then
print("Oops! This piece doesn't fit: ",partsIn[1].Name)
pieceIsFine = false
break
end
end
wait()
end
if not pieceIsFine then
print("Collides!")
chosen:Destroy()
return choosePiece()
end
print("This piece is good!")
return chosen
end
Doesn’t work that fast. Places like 1 track every 30 seconds, which is not good.
What do you want to do exactly
Trying to make a randomly generated cart ride track.