# Rotate movieclip between three different angles

**URL:** <https://forum.kirupa.com/t/rotate-movieclip-between-three-different-angles/261998>\
**Category:** flash\
**Created:** [June 2, 2008, 3:13pm UTC](https://forum.kirupa.com/t/rotate-movieclip-between-three-different-angles/261998 "2008-06-02T15:13:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maaartin](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@maaartin](https://forum.kirupa.com/u/maaartin)\
**Post date:** [June 2, 2008, 3:13pm UTC](https://forum.kirupa.com/t/rotate-movieclip-between-three-different-angles/261998/1 "2008-06-02T15:13:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![DiamondDog](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@DiamondDog](https://forum.kirupa.com/u/DiamondDog)\
**Post date:** [June 2, 2008, 3:40pm UTC](https://forum.kirupa.com/t/rotate-movieclip-between-three-different-angles/261998/2 "2008-06-02T15:40:55Z")

</div>

What does this line do?

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

```

[COLOR=Blue]  
Shouldn’t that be

```auto
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]

---

<div class="post-metadata">

**Author:** ![jakattak](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jakattak](https://forum.kirupa.com/u/jakattak)\
**Post date:** [June 2, 2008, 3:41pm UTC](https://forum.kirupa.com/t/rotate-movieclip-between-three-different-angles/261998/3 "2008-06-02T15:41:13Z")

</div>

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:

```auto

 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;

---

<div class="post-metadata">

**Author:** ![maaartin](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@maaartin](https://forum.kirupa.com/u/maaartin)\
**Post date:** [June 2, 2008, 4:12pm UTC](https://forum.kirupa.com/t/rotate-movieclip-between-three-different-angles/261998/4 "2008-06-02T16:12:54Z")

</div>

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:
