The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 3 of 3

Thread: lining up movieclip with mouse cursor

  1. #1

    lining up movieclip with mouse cursor

    How would you create the effect in this game:
    where the hero's gun/arms align up with the mouse cursor?

    I'm guessing there is trigonometry involved and tracking _xmouse/_ymouse, but I'm not to sure. Any help is appreciated.

    Here's what I have so far. I think the problem is in my math.
    Any ideas.

    onEnterFrame = function ():Void {
        var armY = _ymouse-this.hero_mc.arm_mc._y;
        var armX = _xmouse-this.hero_mc.arm_mc._x;
        var radians = Math.atan2(armY, armX);
        this.hero_mc.arm_mc._rotation = radians*90/Math.PI;
    function addScope():Void {
        scope_mc.onMouseMove = function() {
            this._x = _root._xmouse;
            this._y = _root._ymouse;
            // updateAfterEvent used to refresh stage creating smooth cursor movement

  2. #2
    I didn't really look your code over too well but it looks like you have the right idea. I remember after about an hour of playing around I created this lump of code to get a movieclip to point at the mouse. Hope it helps.

    xTanDist = _xmouse - Arrow._x;
    yTanDist = _ymouse - Arrow._y;
    Radians = Math.atan2(yTanDist, xTanDist)*10
    Rotation = Math.round(5.8*Radians)
    Arrow._rotation = Rotation+90
    Attached Files Attached Files

  3. #3
    Registered User
    The first thing to jump out at me is you're using *90/Math.PI; where I usually would have *180/Math.PI;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012