I’m working on creating an animation in which there are insects randomly moving around - based on tutorials on this site. Does anybody know how to make the insect rotate so that it always points towards the direction of travel.
here’s what’s on my movie clip:
onClipEvent (load) {
scale = (random(100)+50);
this._alpha = random(50)+20;
this._xscale = scale;
this._yscale = scale;
//data you may want to change
width = 650;
height = 150;
speed = Math.round(Math.random()*2)+1;
//initial positions
x = this._x=Math.random()*width;
y = this._y=Math.random()*height;
x_new = Math.random()*width;
y_new = Math.random()*height;
}
onClipEvent (enterFrame) {
//rotation1
this._rotation += rot;
rot = random(500);
setInterval(changeRot, 3000);
//x movement
if (x_new>this._x) {
sign_x = 1;
} else {
sign_x = -1;
}
dx = Math.abs(x_new-this._x);
if ((dx>speed) || (dx<-speed)) {
this._x += sign_x*speed;
} else {
x_new = Math.random()*width;
}
//y movement
if (y_new>this._y) {
sign_y = 1;
} else {
sign_y = -1;
}
dy = Math.abs(y_new-this._y);
if ((dy>speed) || (dy<-speed)) {
this._y += sign_y*speed;
} else {
y_new = Math.random()*height;
}
}
here’s what’s on my timeline:
i = 0;
while (i<5) {
//duplicateMovieClip(box, "box"+i, i);
box.duplicateMovieClip("box"-i, i, 0);
i++;
}