# Pushing a movieclip around / collision detection ++

**URL:** <https://forum.kirupa.com/t/pushing-a-movieclip-around-collision-detection/261887>\
**Category:** programming\
**Created:** [June 1, 2008, 8:55am UTC](https://forum.kirupa.com/t/pushing-a-movieclip-around-collision-detection/261887 "2008-06-01T08:55:59Z")\
**Posts on this page:** 3\
**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 1, 2008, 8:55am UTC](https://forum.kirupa.com/t/pushing-a-movieclip-around-collision-detection/261887/1 "2008-06-01T08:55:59Z")

</div>

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:  
[COLOR=Blue] this.xspeed=-1;  
this.yspeed=0.25;[/COLOR]

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?

---

<div class="post-metadata">

**Author:** ![t0w](https://avatars.discourse-cdn.com/v4/letter/t/ac8455/32.png) [@t0w](https://forum.kirupa.com/u/t0w)\
**Post date:** [June 2, 2008, 5:42pm UTC](https://forum.kirupa.com/t/pushing-a-movieclip-around-collision-detection/261887/2 "2008-06-02T17:42:25Z")

</div>

```auto

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 =/

---

<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 3, 2008, 11:19am UTC](https://forum.kirupa.com/t/pushing-a-movieclip-around-collision-detection/261887/3 "2008-06-03T11:19:53Z")

</div>

I figured it out in the end, but thanks for your input. 🙂
