need help with lookAt function for two objects
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
need help with lookAt function for two objects
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.
- 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
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.
-
- Prole
- Posts: 6
- Joined: Mon Aug 27, 2012 10:21 am
Re: need help with lookAt function for two objects
Something like this gives an angle in Radians.
http://polygeek.com/1819_flex_exploring-math-atan2
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
- 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
This was already featured on the wiki, as a snippet, without the angle correction, though.FrogsFriend wrote:Something like this gives an angle in Radians.
http://polygeek.com/1819_flex_exploring-math-atan2Code: 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
Who is online
Users browsing this forum: rabbitboots and 2 guests