does anyone know how to make a drawn picture (aka an enemy) rotate to the player?
kind of like this
Enemy rotate to player
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
Re: Enemy rotate to player
In enemies code, put computation of an angle towards the player (math.atan2) and use obtained angle for drawing operation.
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
Re: Enemy rotate to player
raidho36 wrote:In enemies code, put computation of an angle towards the player (math.atan2) and use obtained angle for drawing operation.
Code: Select all
enemies.r = math.atan2((enemies.y - player.y), (enemies.x - player.x))
Code: Select all
love.graphics.draw(enemies.pic,(v.x - 15),v.y,0,enemies.scaleX,enemies.scaleY)
Re: Enemy rotate to player
It rotates in opposite direction, starting at 0 degrees (dead right). This is because math.atan2 operates in generic math coordinate grid where Y axis facing up, whereas LÖVE uses computer-graphics-style Y axis that points down. Either use negative of Y argument (just swap player and enemy coordinates), or use negative of function result.
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
Re: Enemy rotate to player
It still doesnt work for some reason.raidho36 wrote:It rotates in opposite direction, starting at 0 degrees (dead right). This is because math.atan2 operates in generic math coordinate grid where Y axis facing up, whereas LÖVE uses computer-graphics-style Y axis that points down. Either use negative of Y argument (just swap player and enemy coordinates), or use negative of function result.
Re: Enemy rotate to player
I just noticed that you said you used math.atan. You should use math.atan2, although the code snippet uses it. For some reason, drawing snippet doens't have any kind of reference to rotation and it's explicitly set to 0. I suggest you posting the real code you use.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Enemy rotate to player
Oh, so that's why angles move clockwise in LÖVE.raidho36 wrote:This is because math.atan2 operates in generic math coordinate grid where Y axis facing up, whereas LÖVE uses computer-graphics-style Y axis that points down.
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
Re: Enemy rotate to player
Ah, it works now. Thanks raidho!raidho36 wrote:I just noticed that you said you used math.atan. You should use math.atan2,
Who is online
Users browsing this forum: Bing [Bot] and 150 guests