PDA

View Full Version : Rotation Code



JapanMan
February 5th, 2009, 08:40 PM
Can someone please post a good way to rotate something to match the mouse? I know it has something to do with the Pythagorean Theorem and sin/cos/tan and MC._rotation, but I'm not sure how to put 2 and 2 together. Using "mcA" and "mcB" (its arms/rotating-thing), this is as far as I can get:

onClipEvent(load){
this.onEnterFrame = function() {
rotateArms();
};
function rotateArms() {
mcA.mcB._rotation = math.tan((_ymouse-this._y)/(_xmouse-this._x));
}
}Thanks.

glosrfc
February 5th, 2009, 09:02 PM
http://www.kirupa.com/forum/showpost.php?p=2397278&postcount=2

JapanMan
February 5th, 2009, 09:10 PM
Thank you >.>

Good to know I was on the right track. I actually got that, except for the radian conversion (thank you, Pre-Calc!).

JapanMan
February 5th, 2009, 09:14 PM
hmmm... wait, it's working... but backwards...

onClipEvent (load) {
this.onEnterFrame = function() {
rotateArms();
};
function rotateArms() {
this.mcB._rotation = Math.atan2(_root._xmouse-this._x, _root._ymouse-this._y)*180/Math.PI+270;
}
}


Ha! Fixed it, just need to subtract the _xmouse from the object's, not vice-versa