# Rotate movieclip between three different angles

I’m writing a fairly complicated game, and what I’m stuck at is rotating a movieclip between three different set angles when it hits the scene bounds. Those three angles should be the initial angle, -30 degrees and +30 degrees. So three different states would be: “normal”, “right” (rotated 30 degrees to the right) and “left”.

The movieclip will be bouncing around the stage, bouncing back when it hits the scenes edges/bounds. When it hits the right edge of the scene, it should be rotated 30 degrees to the left, setting its state to “left”. But if it hits the right edge a second time and is still in the state “left”, it should rotate back to the initial state “normal”.

I’m not very experienced with AS, but I’m thinking the code should be something like:

[COLOR=Blue] mc_angle=“normal”;[/COLOR]

first declare the variable.

[COLOR=Blue] if (mc_angle=“normal”) {
this._rotation = 330;
tip=“right”;
}
if (mc_angle=“right”) {
this._rotation = 360; }
}[/COLOR]

Then tell it to change state.

But obviously that isn’t working, as it seems to jump right to the second if and not rotate the movieclip at all. What am I doing wrong here?

What does this line do?

``````[COLOR=Blue]tip="right";[/COLOR]
``````

[COLOR=Blue]
Shouldn’t that be

``````mc_angle = "right"
``````

so that the value of mc_angle has been changed in preparation for the next time you test it.

Also, in your if( ) statements, shouldn’t you have double equals signs, because you’re
comparing values, not assigning a value to a variable (I’m talking as someone who’s only
ever used AS3. I’m guessing that’s the same whatever version of Flash you’re using?)
[/COLOR]

This might get more response in the Actionscript 2 forum.

Just looking at your IF statement, I’d lean towards making it an IF/ELSE:

``````
if (mc_angle="normal") {
this._rotation = 330;
tip="right";
}
else if (mc_angle="right") {
this._rotation = 360; }
}

``````

However, I’m trying to determine what exactly you’re trying to accomplish based on your description. I understand that you want the rotation to change by +/-30 degrees when it hits the edge of the scene, but I’m not quite sure what you want it to do when it hits repeatedly, etc. Based on it changing =/-30 I’d consider something like the following, depending on which edge it hits:

_rotation += 30;

or

_rotation -= 30;

Well, like I said, my AS isn’t quite there yet. You were both right - thanks for the feedback! This is what worked in the end:

[COLOR=Blue]if (mc_angle==“normal”) {
this._rotation -= 30;
mc_angle=“right”;
}
else if (mc_angle==“right”) {
this._rotation += 30;
mc_angle=“normal”;
}[/COLOR]

:thumb2: