Hey!
I’m currently working on a tsunami-type game.
The tsunamis vary in size by a lot.
The tsunamis are made up of Parts, WedgeParts, and occasional MeshParts (With collision fidelity as hull)
My question is, what is the most efficient method of destroying the parts that the tsunami parts touch?
Right now I’m using GetTouchingParts every x second/s, but I’m not sure this is the best way because of the amount of parts that make up the tsunamis.
The things I currently do for each part touched:
Check if the part can be broken by its name
Decide if the part should even break (Don’t break everything it touches)
Rather make the part BreakJoints, Destroy, or BreakJoints and CanCollide false
Decide the amount it breaks based on its size (tend to destroy smaller parts instead of breakjoints for smaller parts) (None of these are musts and can be changed or removed)
All the tsunami parts are welded to an anchored, invisible core part. The core part is moved by the server by 5 studs every x seconds. The client tweens the core to make it smooth.
What method should I use? Are there any other methods? Do you have any other suggestions? Do you have any experience with my situation?
for index, instance in pairs(Tsunami:GetDescendants())do
if instance:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit then
--do action
end
end)
end
end
do not worry about disconnecting the touch functions, since deleting and respawning it will disconnect for you. I did not add a check for if an instance was already touched, this is just a basis.
honestly I think what you did is also fine as well, since its moving slowly and has time to intersect with a part, unless you are creating repeated connections without disconnecting them. If you need me to explain anything lmk.
My biggest issue is that the tsunamis are randomly generated so I don’t have direct say how many parts are going to be having a .Touched or GetTouchingParts
Since the tsunamis are anchored and moving via CFrame, they technically have no velocity. Thus, if they pass over a part that also has no velocity, the touched event wont fire. It might still fire on players since player’s body parts are always animated and moving, but on a building connected to an anchored baseplate, it wont fire.
On the other hand, GetTouchingParts isn’t a particularly efficient function and given you are going to have many parts connect to that event, it doesn’t seem like a good idea either, unless of course it ends up running fine, in which case go ahead.
However, you could make a separate hitbox on the tsunami run the gettouchingparts function, which would be much more efficient. Or you could use bodymovers and constraints to move the tsunamis, and just use the touched event.