That’s interesting, you essentially implemented a CFrame*Vector3. It might be faster to just use that instead of initializing three Vector3s and calling three dot products from Lua. This is what it’d look like:
local abs = math.abs
function PartContains(part, pos)
local objectPos = part.CFrame:pointToObjectSpace(pos)
local partSize = part.Size --avoid three extra indices! it adds up, you know
return abs(objectPos.X) <= partSize.X / 2 and abs(objectPos.Y) <= partSize.Y / 2 and abs(objectPos.Z) <= partSize.Z / 2
end
I didn’t check if this actually worked, but given your implementation I’m sure it could be rectified if necessary. If you do happen to run a little benchmark, let me know, I’m curious.