# Converting a 3D point on a tilted part's surface to UV Coordinates

Have you ever wanted to convert a 3D point on the surface of a tilted part in Roblox Studio into a Vector2 based on its position on the surface area? It can be a tricky task, but fear not, I’ve got a solution for you!

First, let’s go over the problem. If you have a tilted part, using the `GetSurfacePosition()` method won’t work, as it only returns the surface position on the un-tilted part. Instead, we need to calculate the position of the point relative to the part’s origin, and then use its orientation to determine its position on the surface area.

Here’s an example implementation of a function that does just that:

``````function GetSurfacePosition(part,surfacePoint)
local pos = surfacePoint - part.Position
pos = pos * part.CFrame:Inverse()

-- Calculate the normalized position of the point on the surface of the part
local normX = (pos.X + part.Size.X/2)/part.Size.X
local normY = (pos.Y + part.Size.Y/2)/part.Size.Y

-- Convert the normalized position to UDim2 offset
return Vector2.new(normX,normY)
end
``````

This function takes a tilted `part` and a 3D `point` on its surface, and returns a Vector2 representing the position of the point on the surface area of the part.

The function first calculates the position of the `point` relative to the `part`’s origin in local space using the inverse of the `part`’s orientation. It then calculates the dimensions of the `part`.

Next, it calculates the surface normal of the part at the `point` by constructing a CFrame with the `point` as its origin and a vector pointing up in the Z direction, and then transforming it to local space. The surface normal is the LookVector of this transformed CFrame.

Finally, the function calculates the normalized position of the `point` on the surface of the `part` based on its X and Y coordinates relative to the surface normal, and converts the normalized position to UV Coordinates.

I hope this helps anyone who’s been struggling with this problem. If you have any questions or feedback, feel free to leave a comment below.

4 Likes

Thank you for this resource, I’m sure I will find this helpful in the future. However, if you aren’t looking for help on any scripts, you can instead post it in Community Resources Thank you for your response! I’m glad you found the information helpful. I actually wasn’t looking for help on any specific script, but rather sharing a technique for converting a 3D point on a part’s surface into a UV Coordinate. I thought it would be useful for other developers to know as well. However, I appreciate the suggestion and aswell as that I’ve revamped the post and put it under Community Resources. Thanks again!

1 Like