# Rotating an object 360 & counting revolutions

**URL:** https://forum.kirupa.com/t/rotating-an-object-360-counting-revolutions/275695
**Category:** Uncategorized
**Created:** [November 17, 2008, 6:13pm UTC](https://forum.kirupa.com/t/rotating-an-object-360-counting-revolutions/275695 "2008-11-17T18:13:12Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jeancnicolas](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jeancnicolas](https://forum.kirupa.com/u/jeancnicolas)
#### Post date: [November 17, 2008, 6:13pm UTC](https://forum.kirupa.com/t/rotating-an-object-360-counting-revolutions/275695/1 "2008-11-17T18:13:12Z")

</div>

hi my code is bugged …

I want my line (which does) follow the mouse, like a dial.  
I have converted the degrees into a percentage, so that when the percentage of the rotation reaches 100%, my script counts one revolution, and adds it to its ‘counter’… it kind of works, but sometimes it gets lost and if I go too fast: it misses the revolution count …

here is my code (with the line being ‘line’ as an MC)…

```auto
var degrees:Number = 0;
fixedX = line._x;
fixedY = line._y;
var radians:Number;
var angles:Number;
var counter:Number = 0;
var revolution:Number = 0;
var Last:Number = 0;
var percent:Number = 0;
onEnterFrame = function()
{
    radians = Math.atan2(_ymouse-fixedY,_xmouse-fixedX);
    angles = radians*180/Math.PI;
    
    angles += 90;
    
    line._rotation = angles ;
    percent = Math.round(((angles+90)/360)*100);
    angels.text = percent;
    if (percent > Last)
    {
        counter = percent;
        last.text = "last percent " + Last;
        counta.text = "counter "+counter;
        Last = percent+1;
        if (counter >= 100)
        {
            revolution ++;
            counter -= percent;
            Last = 0;
        }
    }
    rev.text = "revs = " + revolution;
}

```

Any help would be appreciated!
