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)
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('Cha-Cha')
print("Everyone, take a back yall ", relativeVector.Z)