How would I map parts onto a 2D plane to get the x and y offset from a center part (Green) irregardless of orientation?
As an example:
And with rotation:
How would I map parts onto a 2D plane to get the x and y offset from a center part (Green) irregardless of orientation?
As an example:
bluePart.CFrame = greenPart.CFrame + greenPart.CFrame.vectorToWorldSpace(Vector3.new(bla, bla, bla))
You could do something like:
offset = bluePart.CFrame:ToObjectSpace(greenPart.CFrame).p
vsnry and Vulkarin were close, but what you’ll actually want to do is something like this:
function PointToPlaneSpace(point, planeCFrame)
return planeCFrame:PointToObjectSpace(point)
end
--this assumes that the "flat" face of the blue part is the "Front" face.
local pointInPlaneSpace = PointToPlaneSpace(greenPart.Position, bluePart.CFrame)
CFrame:PointToObjectSpace(point)
converts a point in world space (the coordinates you are used to) to the coordinate system that’s centered around CFrame (and rotated according to CFrame). So if point
is 3 studs in front of CFrame
, the Z component of the returned value will be -3. Same with the X (left/right) and Y (up/down) coordinates.
If you only want the X and Y parts, you can get those just by doing
local x, y = pointInPlaneSpace.X, pointInPlaneSpace.Y
If you still want it in the form of a Vector3, you can use this handy trick:
local xyOffset = pointInPlaneSpace * Vector3.new(1, 1, 0)
What? My solution is exactly what they asked for