need help with lookAt function for two objects

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
jtomes123
Prole
Posts: 1
Joined: Tue Feb 05, 2013 10:33 am

need help with lookAt function for two objects

Post by jtomes123 »

Hello i've tried about ten tutorials and it didn't work at all i need basic function that'll return angle from enemies position and players position, thank for all respnds.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: need help with lookAt function for two objects

Post by Robin »

You'll need math.atan2. If you want more specific help, please read the rules and upload a .love of your game.
Help us help you: attach a .love.
FrogsFriend
Prole
Posts: 6
Joined: Mon Aug 27, 2012 10:21 am

Re: need help with lookAt function for two objects

Post by FrogsFriend »

Something like this gives an angle in Radians.

Code: Select all

-- Returns the angle between two points.
function utils.angle(x1,y1, x2,y2)
	local angle = math.atan2(y2-y1, x2-x1)
	if angle < 0 then angle = angle + math.pi * 2 end
	return angle
end
http://polygeek.com/1819_flex_exploring-math-atan2
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: need help with lookAt function for two objects

Post by Roland_Yonaba »

FrogsFriend wrote:Something like this gives an angle in Radians.

Code: Select all

-- Returns the angle between two points.
function utils.angle(x1,y1, x2,y2)
	local angle = math.atan2(y2-y1, x2-x1)
	if angle < 0 then angle = angle + math.pi * 2 end
	return angle
end
http://polygeek.com/1819_flex_exploring-math-atan2
This was already featured on the wiki, as a snippet, without the angle correction, though.
Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests