Custom Axis System - Help Required

Hi, I am trying to get a position of a point relevant to another position with a different axis system and I can’t make it work.

This is what I try to achieve: If the position of the block (let’s call it customAxisSystemOrigin) equals Vector3.new(1,2,3) and the orientation of the axis system (let’s call it customAxisSystemRotation) equals Vector3.new(0,0,0), and the offset/point in the axis system (let’s call it offset) equals Vector3.new(20,20,20), then the final point in the world space will be Vector3.new(21,22,23).

What I need is the way to calculate inWorldPoint using customAxisSystemOrigin,

customAxisSystemRotation and offset.

  • customAxisSystemOrigin is a Vector3 that represents the 0,0,0 point within the custom axis system
  • customAxisSystemRotation is a Vector3 that represents the normal of the custom axis system
  • offset is a Vector3 that represent a certain point on the custom axis system
  • inWorldPoint is a Vector3 that represents the translation of offset from object space (a point in the custom axis system) to world space (a point in the default axis system)

The way I get these variables is using a raycast. I send a ray from position RayOrigin to direction RayDirection that hits at position RayHitPosition at distance RayHitDistance.

I would really appreciate if someone can send me an algorithm or a function that uses these variables to calculate the result inWorldPoint.
Also if any other information like more variables or explanation about something from the above, feel free to ask.

I’ve got it working using this function:

function ToRealPosition(CenterPart,Offset)
    local OrgP = CenterPart.Position
    CenterPart.CFrame = CenterPart.CFrame + CenterPart.CFrame.RightVector * Offset.X
    CenterPart.CFrame = CenterPart.CFrame + CenterPart.CFrame.UpVector * Offset.Y
    CenterPart.CFrame = CenterPart.CFrame + CenterPart.CFrame.LookVector * Offset.Z
    local Position = CenterPart.Position
    CenterPart.Position = OrgP
    return Position
end
--CenterPart is the part that has customAxisSystemOrigin and Orientation (Part)
--Offset is the point in the axis system (Vector3)