How to calculate distance between 2 CFrame values

Its easier said than done. I am not using CFrame.Angles.

Then take the center and substract the position of the black part with the center, then calculate the opposite side in reference to the center and put the black part in that position

That sort of makes no sense? wha

Use some CFrame manipulation.

Code:

local red = -- red part
local black = -- black part
local blue = -- blue part

blue:GetPropertyChangedSignal("CFrame"):Connect(function()
	black.CFrame = blue.CFrame * CFrame.new(0, 0, -15)
	red.CFrame = black.CFrame * CFrame.new(-10, 0, 0)
end)

Dude, thats not the target

[i hate the post must be 3O characters]

Could you explain what the target is then? I genuinely don’t understand.

well see there’s multiple of these that stand still and don’t actually move mid game

to explain

the Red part is the Camera position
The Blue part is the Player position
The Black part would be the distance between the Red and Blue part

What is the goal of this system? Are you trying to make a part follow the camera?

its a camera tracking system for a fnf game

Do you have a reference video of how you want the tracking to work?

this is what it’s doing but

I have other duplicated speakers so u can play in other parts of the default map
and some are rotated and when it’s rotated the camera position isn’t accurate

The Black part is just a reference object it’s not actually in the game
It’s just to show how it works and where it positions the camera

1 Like

The thing you wan’t to make is calculate distance between two points, but you wan’t position depends on orientation too, soo why can’t you use not Part1.Position but rather make your own position, you see, simply you can use look vector to achieve this

local Point1 = (Part1.CFrame * CFrame.new(0,0,-Part1.Size.Z)).Position
local Point2 = (Part2.CFrame * CFrame.new(0,0,-Part2.Size.Z)).Position

local distance = (Point1-Point2).Magnitude -- distance between look vectors of two parts

or if you wan’t to have another part parrarel to another, you could do:

Part2.CFrame = Part1.CFrame * CFrame.new(distance,0,0)

I’m sorry but this wouldn’t work for what I’m trying to achieve

1 Like

soo what you wan’t to achieve, two parts that moves parrarel to each other? yea?

what I need basically is the X Y and Z distance in CFrame

image

so like in this I need the distance from just the side and not how far away the actual part is

so in the image “this point” would be the X value
and the the line going up would be the Z value

I can do this if the parts aren’t rotated but that’s the problem
I need it to be the same at every angle

1 Like

hmmm, soo you need distance split into two axis, you see, every vector is sum of two other vectors, soo here


bad drawing skill, but it’s not matter

soo, even if it’s rotated, you can split vector into X + Y and then use it, use math.abs to do this

well the parts will always face the same direction

but if u rotate all of them so lets say the Orientation is 0,0,0 for each part

then I would do red.CFrame.X - blue.CFrame.X
^ this would be the X distance from each part

but if I changed the orientation and it became something like 0,45,0

then the X - X wouldn’t be accurate anymore since the X and Z are moving and not just the X

sorry if it doesn’t make sense it’s very complicated

1 Like

it’s not complicated, sorry for no reply, the solution will be split vector into 2 components, no matter if it’s rotated by 45 degree or 0, every vector is VectorX + VectorY, you can split this vector into two components, then use pitagorean formula where adjacent^2 + opposite^2 = hypotenuse^2 and whoola, hypotenuse will be your distance

after a lot of searching I finally figured it out from another post

The local relativeVector = pointA.CFrame:ToObjectSpace(pointB.CFrame) was what I needed

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