lets say i have a part that is intersecting with another, so i add a script to make a ray that goes from one part’s position to another, then i want to move it based on its magnitude, so it is only touching, how can i achieve this, especially if the part is big?
What do you want to do this for?
This is a common problem in physics simulations.
A build tool, like the one in plane crazy.
If I were you I would use more of a grid-type system, using a target part (or the target vehicle, or just some random world position like 0,0,0) as the center point for said grid
Grids can be accomplished using simple remainder math
function toGrid(origin,size,pos) --origin is where the grid starts, size is a single number of how big the grid is, pos is the pos you want to move to the grid
local npos = pos-origin
return Vector3.new(pos.X - npos.X % size, pos.Y - npos.Y % size, pos.Z - npos.Z % size)
end
Could you explain the math to me?
What exactly would npos be, or is it just a number with no real context.
And secondly, the math that is being carried out in the vector3.new thing.
What exactly is that number, i know that it is the residue of the difference between the position and origin divided by size, but wouldnt there be a size limit to that, if so, then im not sure I understand the entirety of what is going on in that line.
Also how would I use this, Do i just set the position to this?
npos is the given position offset by the origin
This allows you to change where it snaps to without changing the actual original position
The p- np%size basically gets the remainder, or what to subtract for the point to be placed onto the grid, then does the action of actually subtracting it
This has the effect of, if you have a random point, “snapping” it to a grid
But how does this help with parts intersecting, the problem happens when the part is 4 studs or larger on any axis

