Save-Point
Getting the angle betwen two points - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Archives (https://www.save-point.org/forum-105.html)
+--- Forum: Creation Asylum Archives (https://www.save-point.org/forum-90.html)
+---- Forum: Scripts & Code Snippets (https://www.save-point.org/forum-92.html)
+----- Forum: RPG Maker XP Code (https://www.save-point.org/forum-93.html)
+------ Forum: Code Snippets & Others/Misc (https://www.save-point.org/forum-100.html)
+------ Thread: Getting the angle betwen two points (/thread-6623.html)



Getting the angle betwen two points - Guedez - 12-20-2006

Getting the angle betwen two points
by Guedez
Dec 20 2006

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


I was going to try to rotate a sprite, so i made a definition that gives the angle between two points, but i discovered that i can't rotate a sprite, and to not just delete this useful(for somebody else) definition i am posting it here.

Code:
def get_ang(sx,sy,tx,ty)
    if tx < sx
      d = sy
      sy = ty
      ty = d
    end
    pi = 3.141592654
    rad = pi/180
    grau = (Math.atan2( -(tx - sx), -(ty - sy))/rad).abs.ceil
    grau += 180 if tx < sx
    return grau
  end