A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: atan2 ?

  1. #1
    Junior Member
    Join Date
    Jul 2002
    Posts
    7
    Hello
    I have a MC that is just a line, there is another MC in that with these object actions:
    Code:
    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 :))

  2. #2
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    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)

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