Results 1 to 8 of 8

Thread: Enemy Rotation

  1. #1
    Jephz's Avatar
    106
    posts
    The Penguin n00b

    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?
    Don't you ever, ever, EVER call me a Noob. I mean it!

  2. #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
    Click my sig.

  3. #3
    Jephz's Avatar
    106
    posts
    The Penguin n00b
    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:
    http://spamtheweb.com/ul/upload/1006...e.php?lightbox
    Don't you ever, ever, EVER call me a Noob. I mean it!

  4. #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. #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. #6
    Jephz's Avatar
    106
    posts
    The Penguin n00b
    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?
    Don't you ever, ever, EVER call me a Noob. I mean it!

  7. #7
    209
    posts
    Registered User
    Quote Originally Posted by Jephz View Post
    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?

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

  8. #8
    Jephz's Avatar
    106
    posts
    The Penguin n00b
    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.
    Don't you ever, ever, EVER call me a Noob. I mean it!

Thread Information

Users Browsing this Thread

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
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012