_rotation?

Ive this problem with rotating an object.
What I want to do is rotate an object to
108 degrees than rotate it back to 72 degrees.

So what I did was:
[AS]
onClipEvent (load) {

// set speed
rotationSpeed = 2;

}

onClipEvent (enterFrame) {
// start the motion
_rotation += rotationSpeed;

// rotate back when gone to far.
if (_rotationSpeed >= 108) {
rotationSpeed *= -1;

// stop at 72 degrees
if (_rotation == 72) {
_rotationSpeed = 0;
}
}
}
[/AS]
Atleast thats what I thought would work. but the stupid thingie rotates to 108 degrees, then rotates back the other way BUT DOESNT STOP AT 72 DGREES!!!

what am I doing wrong?

Nasier

You should test on rotation in the first test.

And you need to move the second test ‘out’ a bit. Like this:

[AS]
// rotate back when gone to far.
if (_rotation >= 108) {
rotationSpeed *= -1;
}

    // stop at 72 degrees
    if ((_rotation == 72) && (rotationSpeed < 0)) {
            rotationSpeed = 0;
    }

[/AS]

In your code, the rotation has to be larger than or equal to 108 and at the same time be 72. It can’t be done.

Hope that helps.

onClipEvent (load) {
        
        // set speed
        rotationSpeed = 2;
        
}

onClipEvent (enterFrame) {
        // start the motion
        _rotation += rotationSpeed;
        
        // rotate back when gone to far.
        if (_rotation >= 108) {
                rotationSpeed *= -1;
        }         
        // stop at 72 degrees
         else if (_rotation == 72) {
                        _rotationSpeed = 0;
                }
        }

Shouldn’t it be this? Cuz I don’t see why he is checking to see if the rotationSpeed is less than 108 (which it is).

Steve, your code will stop the first time _rotation reaches 72, so it’ll never get to 108.

I check on rotationSpeed to get the code to stop at 72, but only on the way back.

I’m no expert on _rotation or anything but just out of curiosity - is it going back 72 degrees from 108? i.e. is it stopping at 36? Maybe you need to say:

// stop at 72 degrees
else if (_rotation == 36) {

?

Just a guess anyway . . .:whistle: