I am trying to get an angle between two points
The formula for doing this is inverse tan(absolute y value / absolute x or z value).
In my case:
math.atan(height / 1.5)
I know both height and 1.5 are the correct values. However, I am having issues with the output. Apparently, the output of atan is a radian. Sure, so when I put it into a CFrame angle, it should give the correct rotation (without me needing to use math.rad).
Of course, it doesn’t, I’ve tried multiple things such as using math.deg or math.rad or neither. I’ve tried converting my radian back into degrees then using math.rad in the CFrame.
Here’s the code I’m using (it’s sloppy, right now I’m not trying to make it look neat)
local height = math.abs(npoint.Position.Y) - math.abs(point.Position.Y)
local pyth = 1.5^2 + height^2
pyth = pyth^0.5
local rot = math.atan(height / 1.5)
local cfra = CFrame.new(Vector3.new(point.Position.X, point.Position.Y, point.Position.Z)) * CFrame.fromEulerAnglesXYZ(math.rad(rot), 0, 0)
beam.Length = pyth
beam.CFrame = cfra
I think I’ve tried using CFrame.Angles instead of CFrame.fromEulerAnglesXYZ however, I can’t be sure. It still shouldn’t affect it.
I’ve concluded that the issue is in math.atan and my use of the output, I know both variables in the tangent are correct. All help appreciated