How to find the closest edge in a part to another

image

how would i find the point inside the blue part closest to the red part???

Uhm, you didn’t exactly provide many details about what you want, but you can ray casting from the blue part to the red, and find the position at which the ray hits the blue part.

You can also use WorldRoot:FindPartsOnRayWithWhitelist to make it so it only collides with the blue part.

To get the ray direction, you could do:

CFrame.lookAt(red.Position,blue.Position).LookVector

but then it wont correct since of the orientation and shape, that only works for perfect spheres, in this case il be working with rectangles

Ok nothing you are saying really makes much sense, but some vector3 math should do the trick.

image
the ray would hit the middle which isnt the closest, and i would like it to get the nearest point inside the blue part, and efficiently if possible

Try using .Magnitide since it returns a length of a vector (distance)

Again some basic vector3 math could do the trick. You could clamp the X position of the red cube with the maximum being the

blueCube.Position.X+(blueCube.Size.X/2)

And the minimum being

blueCube.Position.X-(blueCube.Size.X/2)

You would do the same for Y and Z.

Then the fully clamped Vector3 position would describe a point on the surface of the blue cube closest to the red cube.

1 Like