Finding the degree from one part to another

You can write your topic however you want, but you need to answer these questions:

  1. **What do you want to achieve? Finding the degree from one part to another.

I want to find the angle in degrees from the origin part to the red yellow green and blue parts. How would I script this?

  1. What solutions have you tried so far?
    I tried a couple of solutions but they would come up with inaccurate results
  1. Get the vector from origin to point A.
  2. Get the vector from origin to point B.
  3. Use vectorA:Angle(vectorB).
    4, Convert the result to degrees with math.deg()
local a = workspace.a.Position-workspace.b.Position 
local b = workspace.a.Position-workspace.c.Position 
print(math.deg(a:Angle(b))) -- 90

MB I messed up in communicating, lets say that north of the origin is 0 or 360 degrees, what is the world angle of the origin part to the green part. I wrote 45 degrees because that’s roughly what it should be

So you mean, similar to a compass?

Here you go

local referenceDirection = Vector3.new(1, 0, 0) -- Reference direction along the x-axis

-- Function to calculate the angle in degrees between the reference direction and another vector
local function calculateAngle(origin : Vector3, target : Vector3)
	-- Calculate the angle in radians between the referenceDirection and the vector
	local angleRad = referenceDirection:Angle(vector - origin)
	return math.deg(angleRad) -- Convert to degrees
end
1 Like