# Help with realistic insect movement

**URL:** <https://forum.kirupa.com/t/help-with-realistic-insect-movement/183392>\
**Category:** Uncategorized\
**Created:** [March 26, 2006, 5:42pm UTC](https://forum.kirupa.com/t/help-with-realistic-insect-movement/183392 "2006-03-26T17:42:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sinjun68](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@sinjun68](https://forum.kirupa.com/u/sinjun68)\
**Post date:** [March 26, 2006, 5:42pm UTC](https://forum.kirupa.com/t/help-with-realistic-insect-movement/183392/1 "2006-03-26T17:42:54Z")

</div>

Hello All.  
I have a question about this script. I have a mc of a little beetle, and found this script to get it to move around randomly. The trouble is when it rotates it does not actualy show the mc rotating. Example: if beetle is facing the 12 oclock position and the next randomly chosen position is rotated to the 6 oclock, it just appears there with no steps in between. I have very little knowledge of actionscript, but what I’m after is having the beetle walk a little, pause briefly slowly turn to another direction (either clockwise, or counterclockwise, pause briefly, and walk forward. All with some randomness. Random lengths of walking, pausing, and rotating. Is there a simple way to modify this code to actualy show the process of it rotating?  
Any help would be gratly appreciated.  
-Sinjun  
code below:

var dice;  
var speed;  
var rotation;  
var x;  
var y;  
var angle;  
var intervalID;  
//  
function rollDice() {  
dice = Math.random()\*100;  
trace(dice);  
if (dice\<5) {  
moveInsect();  
}  
}  
function moveInsect() {  
rotation = Math.random()\*360;  
speed = 5;  
//random length of time to move 1 to 2 seconds  
intervalID = setInterval(stopInsect, Math.random()_2000+1000);  
}  
function stopInsect() {  
speed = 0;  
clearInterval(intervalID);  
}  
insect.onEnterFrame = function() {  
rollDice();  
this.\_rotation = rotation;speed = 5;  
this.\_x += Math.sin(this.\_rotation_(Math.PI/180))_speed;  
this.\_y += Math.cos(this.\_rotation_(Math.PI/180))_speed_-1;  
};

PS a demo of a similar effect I am trying to achieve can be seen at the top of this page (ladybug).  
[http://www.myflashxml.us/xmlswf/v12b3/index.html](http://www.myflashxml.us/xmlswf/v12b3/index.html)
