A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Complex Rotating Turret (AS2)

  1. #1
    Junior Member
    Join Date
    Sep 2002
    Posts
    17

    Arrow Complex Rotating Turret (AS2)

    I'm trying to make a turret that points towards the cursor, but lags when the cursor is moved. I can get this to work, however I am running into problems when the cursor crosses from quadrant 4 to 3 (and vice versa). The problem is that the function I am using to control the turret's rotation rotates the turret around the opposite direction almost 360 degrees to get to the new position, instead of moving the few degrees it needs to. Here is a picture to help explain.
    Last edited by FViral; 06-12-2010 at 04:31 PM. Reason: im a dork

  2. #2
    Junior Member
    Join Date
    Nov 2007
    Posts
    14
    So what is your current code?

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    see this thread here

    gparis

  4. #4
    Junior Member
    Join Date
    Sep 2002
    Posts
    17
    My code looks like so:
    Actionscript Code:
    onClipEvent (enterFrame) {
        xdiff = this._x-_root.cursor._x;
        ydiff = this._y-_root.cursor._y;
        hyp = Math.sqrt(Math.pow(xdiff, 2)+Math.pow(ydiff, 2));
        phi = (180/Math.PI)*Math.asin(ydiff/hyp);
        if (xdiff>0) {
            phi = 90-phi;
            this._rotation -= (0.1)*(this._rotation+phi);
        } else if (xdiff<0) {
            phi = phi-90;
            this._rotation -= (0.1)*(this._rotation+phi);
        }
    }
    It has some more bells and whistles to it but this is the important part.

Tags for this Thread

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