The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

1. ## Enemy Rotation

Hey guys, I have a problem. I need the enemy to rotate in the direction of the player. In other words, as the player moves, the enemy will rotate in the direction of the players movement. I'm trying to make a real time battle system like Athalina Rpg/Hero rpg. Any hints?

2. 1,532
posts
I make half sense
search the forums you...

I kindly hint that you might just try to search the forums for simular examples/questions and tutorials

3. Ok...I found a code when searching on Google, the rotation works but the enemy is always facing the wrong way. Heres the code:

Code:
```onClipEvent(enterFrame) {
var xd = _root.pc._x-_root.enemy._x;
var yd = _root.pc._y-_root.enemy._y;
var ang = Math.atan2(yd, xd);
_root.enemy._rotation = ang*(180/math.PI);
}```
And heres the swf:

4. 209
posts
Registered User
Well... Think back to highschool. Remember trig? Look, when you position the hero directly north of him the enemy points left, so his rotation is at -90 because rotation in movie clips are oriented with up as 0. So, if you want to make -90 become 0, add 90 degrees. And just because your sig challenged me. Noob.

5. function focus(obj,mx,my,correction)
{
obj.rot = -Math.atan2((obj._y - my),(mx - obj._x ))*180/Math.PI;
obj._rotation = obj.rot-correction;
}

obj=ENEMY
mx= player._x
my= player._y
correction = type 0 normally, unless you can spot an angle error. you said your enemy faced the wrong way? keep typing in "correction" angles like 90, -90, 45, -45 .. or change your enemy's idle state.

6. Dude, I'm 13, still in middle school. Not really familiar with trig yet.

and suvenier, your code is too complicated for me, I'm still new to AS.

Can anyone make things a little more simple for me to understand?

7. 209
posts
Registered User
Originally Posted by Jephz
Dude, I'm 13, still in middle school. Not really familiar with trig yet.

and suvenier, your code is too complicated for me, I'm still new to AS.

Can anyone make things a little more simple for me to understand?

Ah, sorry man, sometimes I forget about that possibility.

8. Ok thanks everyone, I got it fixed. I just added 90 degrees to the rotation, and now it works.
Last edited by Jephz; June 11th, 2008 at 02:18 AM.

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•