How to get an object to rotate and follow another object?

Hi there everyone! I am making a game in flash. I am trying to get an enemy spaceship to follow the hero space ship whereever it goes. I got it to follow it but I want it to rotate when if follows the hero ship. Please help me thanks :slight_smile:

Also this is the code I am currently using.

This is the enemy spaceship code:
The enemy ship moves, but I want him to rotate when he follows the hero’s ship. Thanks :slight_smile:

onClipEvent (enterFrame) {
if(_root.box1._x > this._x+100) {
this._x += 5;

}
if(_root.box1._x < this._x) {
	this._x -= 5;	
	
}
if(_root.box1._y < this._y) {
	this._y -= 5;
		
}
if(_root.box1._y > this._y) {
	this._y += 5;
	
}

}

What do you mean by rotate?

Do you mean have a left and right state?

Try using Math.atan2(dY, dX)

Where dY is the distance between the ships along the y axis. And dX is the distance between the ships along the x axis.

Note: the value returned is in radians.

Yes right and left rotate. Like I have it where the hero ship is getting chased by the enemy ship. But when I rotate the hero ship i want the enemy ship rotate with it and continues to chase the hero ship.

Can you post an example or something similar?

I’m still confused by your use of the word rotate, and whether you mean turn around a centre point, or flip left and right.

Thanks.

Hi this site doesn’t let you post any links to fla. The perfect example is Dead frontier (The flash version). How the enemies follow the hero around. I want it to where the enemy ship turn around towards the hero ship and follow him. Please help! :slight_smile:

OK, thanks that helped. Now I see what you mean. :slight_smile:

Sorry, I can’t help you with this problem. :frowning: