You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to find a method that allows me to detect certain parts which cannot be detected except in a square using Region3 (seemingly).
What is the issue? Include screenshots / videos if possible!
Region3 doesn’t work, if I understand it correctly, it only detects within a square.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Still looking. I looked for solutions for my problem but I didn’t find any. I don’t need anyone to script it, would just like a point in the right direction.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
You could do a magnitude check, and then do some math to see if a part is in a sphere.
Edit: Here is a code example:
for i, v in pairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
local magnitude = (v.Position - Sphere.Position).Magnitude
if magnitude <= (Sphere.Size.X + Sphere.Size.Y + Sphere.Size.Z) / 3 then
-- Boom. Part is in the sphere
-- Do something...
end
end
end
I haven’t, but when I create a sphere part it is surrounded by the square highlight, which exceeds the physical sphere and was confused. Will the GetTouchingParts() include the parts that are also inside that highlight/selection or just within the physical sphere?
Why is a magnitude check more preferred than the GetTouchingParts() function? It doesn’t look more efficient? Is there some kind of outside variable that may affect it?
Magnitude is going to be cheaper than using GetTouchingParts because it doesn’t preform any intersection tests, all Magnitude is the distance from 2 vectors.
Also i +1GetTouchingParts, because you might run into some rotation and size issues/complications with just using Magnitude alone (if you care about accuracy).
Magnitude isn’t preferred, because then you would have to check lots of instances 10 times or more per second. Unless, of course, there are not many instances.
local Part = -- The sphere with can collide set to false
Part.Touched:Connect(function() end)
local Parts = Part:GetTouchingParts()
if #Parts > 0 then
for i,v in pairs(Parts) do
print(v)
end
end
What are you talking about? Every can collide true part has a touched event. In games there might be thousands of them! Please don’t blabber out of nowhere(sorry for being rude). The reason I didn’t disconnect it is because they might have to run the function the whole game.
@WarInEuropeRBLX If there are many tiles, using the GetTouchingParts() method would be better, unless you are only using magnitude occasionally. Imagine looping through 100 parts every second. But it won’t cause much of a difference.
The sphere will be created once and will run only to detect 19 particular parts within itself. It wouldn’t take a lot of resources, I think, but it would be best for the game, practice, and familiarity.
The sphere will afterwards be deleted after the detection, as it would no longer be used.