# Thread: Pushing a movieclip around / collision detection ++

1. 10
posts
Registered User

## Rotating a MovieClip ++

Hi,

So, I'm working on a banner which will be using a lot of techniques usually used in games, such as collision detection and user interaction to change the direction and of a movieclip.

I have a movieclip on the scene that starts out moving around the screen at a certain x and y speed:
this.xspeed=-1;
this.yspeed=0.25;

This movieclip is reflected back when it hits the edges of the scene (xspeed or yspeed is reversed). Lets say that when the movieclip hits the right edge of the scene and is reflected, I also want it to rotate +30 degrees. However, if has already been rotated 30 degrees and hits that same right edge again, it should rotate back to the original angle.
Any thoughts on how to accomplish this?

Also, beneath that main movieclip is a shadow. This shadow should shrink or grow and decrease or increase its alpha-value, depending on the y-coordinate of the main movieclip (or distance between the shadow and the main movieclip).
How would I best deal with this situation?
Last edited by maaartin; June 1st, 2008 at 02:05 PM. Reason: old problem solved, new ones come up

2. Code:
```var xspeed:Number = 5;
var yspeed:Number = 0.025;

//set square to wall1 position (hitTest them to start it up)
square._x = wall1._x;

onEnterFrame = function ()
{
if (square.hitTest(wall1))
{
square._rotation = 0;
square.onEnterFrame = function ()
{
this._x += xspeed;
this._y -= yspeed;
}
}

if (square.hitTest(wall2))
{
square._rotation = 30;
square.onEnterFrame = function ()
{
this._x -= xspeed;
this._y += yspeed;
}
}
}```
Okay I posted something before but the idea it turned out was convoluted so I ended up doing a simple hitTest to make the movieClip go back and forth.

I made 3 movieClips, square is the one that moves around. Wall 1 is left border, wall 2 is right border.

I'll figure out the other parts and let you know. There may be a better way to do this stuff so someone else should pipe up.

*** Oh **** woops, I didn't notice that you had solved your problem =/
Last edited by t0w; June 2nd, 2008 at 02:57 PM.

3. 10
posts
Registered User
I figured it out in the end, but thanks for your input.