# Help with Random Movement!

**URL:** <https://forum.kirupa.com/t/help-with-random-movement/158225>\
**Category:** flash\
**Created:** [August 8, 2005, 11:47am UTC](https://forum.kirupa.com/t/help-with-random-movement/158225 "2005-08-08T11:47:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pattt](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@Pattt](https://forum.kirupa.com/u/Pattt)\
**Post date:** [August 8, 2005, 11:47am UTC](https://forum.kirupa.com/t/help-with-random-movement/158225/1 "2005-08-08T11:47:23Z")

</div>

I’m working with a randomly moving MC, and now it looks good  
exept the collisions with the level.

When it hits the level it gonna rotate and go another way.  
I don’t want it go **through** the walls.

Please help! ☹

```php
 
 
onClipEvent (load) {
 xx = -(Math.cos(this.ro._rotation*(Math.PI/180)))*speed;
 yy = -(Math.sin(this.ro._rotation*(Math.PI/180)))*speed;
 this.ro._rotation = random(360);
 radie = 9;
 speed = 2;
 rot = random(30)-random(30);
}
onClipEvent (enterFrame) {
 rot *= 0.9;
 if (rot == 0) {
  rot = random(30)-random(30);
 }
 xx = -(Math.cos(this.ro._rotation*(Math.PI/180)))*speed;
 yy = -(Math.sin(this.ro._rotation*(Math.PI/180)))*speed;
 _x += xx;
 _y += yy;
 this.ro._rotation += rot;
 /*------------------------------DOWN HERE------------*/
 for (i=0; i<radie*2; i++) {
  if (_root.coll.hitTest(_x, _y-radie+i+yy, true)) {
   this.ro._rotation -= (this.ro._rotation/2);
   rot = random(30)-random(30);
   if (_rotation == 0) {
	this.ro._rotation = random(360);
   }
  }
  if (_root.coll.hitTest(_x-radie+i+xx, _y, true)) {
   this.ro._rotation -= (this.ro._rotation/2);
   rot = random(30)-random(30);
   if (_rotation == 0) {
	this.ro._rotation = random(360);
   }
  }
 }
 if (_root.coll.ground.hitTest(_x, _y, true)) {
  this.ro._rotation -= (this.ro._rotation/2);
  rot = random(30)-random(30);
 }
}

 
 

```
