How could I detect when a part is near another part constantly without decreasing performance?
How about checking the magnitude/distance of the parts to ensure its close.Also you can use runservice heartbeat to constantly check the distance
I’m trying to snap a block to the nearest face of another block, would this work for it?
that’s be performance heavy if your checking the entire workspace, what i’ve done for my conveyor belt system is using workspace:PartsInParts with the ray query set to whitelist and i have the belt sides tagged so each belt can find the previous belt or the next belt.
You can do a similar process where you add all the parts you want to check into a tag with collection service and check to see if it’s colliding with the other part, i hope this makes sense i can write a basic script for it but it won’t be for a couple hours possibly
So would I have to add invisible sides or a part extruding outwards for each face of a block to snap it like a hitbox? Also, I know what a ray is but what’s a ray query
yeah they’d be like invisible hit points, i’ll see if i can make you an example script
I haven’t tested it but something like this should snap work.
local CollectionService = game:GetService("CollectionService")
function getSnap(snap: BasePart)
local awSnaps = CollectionService:GetTagged("awsnap") --// haha, all snaps
local snapulquery = OverlapParams.new()
snapulquery.FilterType = Enum.RaycastFilterType.Include
snapulquery.FilterDescendantsInstances = awSnaps
local snapInSnaps = workspace:GetPartsInPart(snap, snapulquery)
return #snapInSnaps > 0 and snapInSnaps[1] or false
end
I’m not sure if I understood this topic correctly, but if the use case is for building (thats what I understood from the face snapping), why not use raycasts instead?
Whats the exact use case?
GetPartsInPart can sometimes be performance intensive if used too much.
Your wanting me to ray cast from all the faces that the object has? isn’t that also performance intensive or I’m just getting it all wrong
Try to group up your checks, and maybe:
local rs = game:GetService("RunService")
rs.Stepped:Wait() -- helps regulate them at a realistic rate in loop(s)
one way…
local rs = game:GetService("RunService")
while rs.Stepped:Wait() do
-- program friendly loop
end
Can you describe what your use case is?