Getting the angle betwen two points
#1
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
}




Users browsing this thread: 2 Guest(s)