# Rotating object to point forward

**URL:** <https://forum.kirupa.com/t/rotating-object-to-point-forward/151276>\
**Category:** Uncategorized\
**Created:** [June 14, 2005, 2:51pm UTC](https://forum.kirupa.com/t/rotating-object-to-point-forward/151276 "2005-06-14T14:51:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![boua5828](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@boua5828](https://forum.kirupa.com/u/boua5828)\
**Post date:** [June 14, 2005, 2:51pm UTC](https://forum.kirupa.com/t/rotating-object-to-point-forward/151276/1 "2005-06-14T14:51:17Z")

</div>

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:

```auto
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:

```auto

i = 0;
while (i<5) {
	//duplicateMovieClip(box, "box"+i, i);
	box.duplicateMovieClip("box"-i, i, 0);
	i++;
}

```
