How To Get Point/Distance - How To get Position Relative Rotation To Part

Hi, I am trying to get the position x(or)z distance between point A and point B

But The problem is my point A is rotating (It is a car) and I am trying to get the distance that is the distance to the right of point A.

I tried for few days, different methods like get relative CFrame but I couldn’t figure it out.
I currently have 2 ideas to do it.
1- Find a way to rotate X,Y,Z axis’s.
2-Use math to find output (Shown in the picture) (I just need the idea to do the formula)

Thank you For support.

You want to project the difference between A and B onto the big X axis. This is a dot product, so it would look like: (PositionA - PositionB):Dot(BigXAxis)

Here’s a useful code that you might use in this case:

local pointA
local pointB

--pointA to pointB is calculated as B - A

local relativeVector = (pointB.CFrame - pointA.CFrame)
local distance = relativeVector .Magnitude
local direction = relativeVector .Unit

corrected code. Here’s another method to find how much “right” is relative to something

local pointA = workspace:WaitForChild('p1')
local pointB = workspace:WaitForChild('p2')
--pointA to pointB is calculated as B - A Method

local relativeVector = (pointB.Position - pointA.Position) --its actually position not cframe
local distance = relativeVector.Magnitude
local direction = relativeVector.Unit

--ToObjectSpace method

local relativeVector = pointA.CFrame:ToObjectSpace(pointB.CFrame)

--Answer :) 

print('Everyone, slide to the right', relativeVector.X)


print("Everyone, take a back yall ", relativeVector.Z)

Thank you so much for the script and help. It helped me a lot. I was trying to figure out for last 2 days.

(and sorry for the short clip there was a 10m limit)
(This is just a testing space and nice print messages btw : ) )
-Thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.