PDA

Click to See Complete Forum and Search --> : atan2 ?



thanton3
07-11-2002, 10:53 AM
Hello
I have a MC that is just a line, there is another MC in that with these object actions:


onClipEvent(load){
var r = 150;
}
onClipEvent(enterFrame){
var angleTarget = 0;
if (Math.pow(_xmouse, 2) + Math.pow(_ymouse, 2) <= Math.pow(r,2)){
angleTarget = Math.atan2(this._ymouse, this._xmouse) ;//* 180/Math.PI;
}
this._parent._rotation = angleTarget * 180/Math.PI;
trace(angleTarget * 180/Math.PI);
}

I think that's all I should need, I just want the line to point at the mouse if the mouse is within a certain radius... the IF works fine, but setting the rotation is screwy, it flips from an almost correct angle to 0.
Anywone know why?

(btw this isn't really my first post here, I just changed emails and forgot my password. Please don't ignore my question based on the fact that it appears I haven't answered any other posts yet :))

ericlin
07-14-2002, 09:22 AM
Try:

this._parent._rotation += angleTarget * 180/Math.PI;

after you set a new rotation, the _xmouse and _ymouse is refer to a new coordinate system.

If you use _root._xmouse and _root._ymouse, then you can set this._parent._rotation=angleTarget*180/Math.PI;
(assume the _root does not rotate)