A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: rotation question

  1. #1
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254

    rotation question

    I have something in my game which I rotate to face the mouse. Pretty simple. To make things easier with animation I flip the character using scaleX respectivly for left and right movement. Now this causes a problem with the rotation. I set the rotation with the following.

    dx = stage.mouseX - this.x;
    dy = stage.mouseY - this.y;

    radians = Math.atan2(dy,dx);

    this.arm.rotation = radians * 180 / Math.PI;

    This works perfect when the scaleX is 1 but when I set it to -1 it causes problem like I thought it would. Its not like it faces the exact oposite direction though.

    But I thought it would be as simple as multiplying (radians * 180 / Math.PI * scaleX). But I realise radian values weird and not like degrees. So I can't figure out how to flip the value properly. Any thoughts?
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Try this with scaleX:

    dx = Math.abs(stage.mouseX - this.x);
    dy = stage.mouseY - this.y;
    radians = Math.atan2(dy,dx);
    this.arm.rotation = radians * 180 / Math.PI;

  3. #3
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254
    Thanks tonypa that seems to work great. Is there a way to enable full 360 rotation for both scaleX -1 and 1. Using your above method gives me 180 degree up and down movement in the direction the mc is facing.
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Maybe (have not tested it):

    dx = (stage.mouseX - this.x) * this.scaleX;

  5. #5
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254
    Thanks tony, Ill give it a shot.
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

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