Get rotation between points in degrees (SOLVED)

Hi,
I’m using this code to get rotation from current position to another position:

  local angle = math.atan2(self.target.y - go.get_position().y, self.target.x - go.get_position().x)

Then the code will set rotation of another object to get his rotation in degrees by euler.z.

  go.set_rotation(vmath.quat_rotation_z(angle), "rotor")
  rot = math.floor(go.get(".", "euler.z"))

But the information obtained by euler.z is not in the 360 degree spectrum, but in numbers from -180 to 180, so I’m still converting the number to the 360 degree spectrum using this code:

rot = rot + 360
if rot > 360 then 
   rot = rot - 360
end

It’s quite complicated and I also need a second object, which only serves to set the rotation to a certain point, so that it can then provide the information in euler.z, which is then converted.

local angle = math.atan2(self.target.y - go.get_position().y, self.target.x - 
go.get_position().x)

Could I somehow avoid this and get the information straight by converting the vmath.vector4 rotation obtained from this line of code to a degree? And why is euler.z not in the 360 degree spectrum at all?
Thank you in advance for your answers.

I am confused… any angle computation (and the set euler.z function) should work perfectly well in the range -180.0, 180.0. Or any other range “covering” 360 degress… Indeed it seems to me that atan2 returns an angle in radians and not degree… But maybe I am missing something

2 Likes

Thank you very much, I’ve already figured it out, just use math.deg (angle).

1 Like