Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Snippet: Get angle from two vectors — Gideros Forum

Snippet: Get angle from two vectors

MikeHartMikeHart Guru
edited January 2012 in Code snippets
Hi folks,

here is a little function that determines the angle of two given vectors in degrees.
vecAngle = function(startX, startY, targetX, targetY)  
	local xdiff = targetX - startX
	local ydiff = targetY - startY
    	local ang = math.atan2( ydiff, xdiff )
	ang = math.deg(ang) + 90.0
	if ang < 0 then 
		ang = 360.0 + ang
	end
	return ang
end

Likes: atilim, Mells, oleg

Dislikes: Lobo

Tagged:
+1 -1 (+3 / -1 )Share on Facebook
Sign In or Register to comment.