-
Dance Monkey Dance!
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"
-
Senior Member
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;
-
Dance Monkey Dance!
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"
-
Senior Member
Maybe (have not tested it):
dx = (stage.mouseX - this.x) * this.scaleX;
-
Dance Monkey Dance!
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|