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?
search the forums you…
I kindly hint that you might just try to search the forums for simular examples/questions and tutorials
Ok…I found a code when searching on Google, the rotation works but the enemy is always facing the wrong way. Heres the 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:
http://spamtheweb.com/ul/upload/100608/47199_battle.php?lightbox
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.
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.
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.
Fidodo, your the first to answer the challenge. You can have a cookie ^^.
Can anyone make things a little more simple for me to understand?
[quote=Jephz;2340435]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.
Fidodo, your the first to answer the challenge. You can have a cookie ^^.
Can anyone make things a little more simple for me to understand?[/quote]
Ah, sorry man, sometimes I forget about that possibility.
Ok thanks everyone, I got it fixed. I just added 90 degrees to the rotation, and now it works.