A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [help] need hlp plz

Hybrid View

  1. #1
    Junior Member
    Join Date
    Feb 2004
    Posts
    5

    [help] need hlp plz

    hi
    im making a game and i want the character to move with the arrow keys but face in the direction of the mouse... kinda like a top-down fps (pple who play cs or other fps should know what i mean)

    well anyways
    i got the guy to move around (easy part) but i cant get him to face in the direciton of my mouse

    this is the code im currently using (i took out the mouse part cuz it was screwing it up)
    if any 1 can help me i would greatly appreciate it

    onClipEvent (load) {
    speed = 2;
    }
    onClipEvent (enterFrame) {
    if (key.isdown(key.RIGHT)) {
    play();
    _x+= speed;
    }
    if (key.isdown(key.LEFT)) {
    play();
    _x-= speed;
    }
    if (key.isdown(key.UP)) {
    play();
    _y-= speed;
    }
    if (key.isdown(key.DOWN)) {
    play();
    _y+= speed;
    }

    }
    i like cheese

  2. #2
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    code:

    // anywhere in main timeline
    var RAD2DEG = 180 / Math.PI;

    // on the MC enterFrame:
    var dx = _root._xmouse - this._x;
    var dy = _root._ymouse - this._y;
    var angle = Math.atan2(dy, dx);
    this._rotation = (RAD2DEG * angle) + 90;




    Here you go buddy, becasue I like your name and cheese also...
    jonmack
    flash racer blog - advanced arcade racer development blog

  3. #3
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    Please use a descriptive title and proper words, it isn't a text message...

    Your looking at basic trigonometry to solve your problem:

    http://www.moor47.fsnet.co.uk/tuts/trig_example.fla

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  4. #4
    Junior Member
    Join Date
    Feb 2004
    Posts
    5
    thanks for your help

    imma try out the code and see how it works
    i like cheese

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center