Page 1 of 1

Enemy on target

PostPosted: Wed Jun 27, 2012 2:52 am
by mcavalcanti
Hello! Imagine a game like Asteroids (http://www.oldsoftware.com/softimg7/atari2.jpg), where your spaceship moves in circle/rotation. I just did the sprite rotation and the controls. It's ok. What I need to do to calculate that the spaceship is "looking" to an enemy? In other words, how to know the enemy is "on target"?

To move the ship, I'm using something like this:
Key Down >> Right:
ang-=1;
if(ang<0){ang=180;}
animpos=ang;

But I need a way to know the ship is pointing to an enemy.

Re: Enemy on target

PostPosted: Wed Jun 27, 2012 5:45 am
by skydereign
If you have the animation setup already, then it is just a matter of getting the animpos code. One thing that will make this easier is if you have the rotation started facing right, and rotate counterclockwise. Then you can just use something like this.
Code: Select all
animpos = angle/360.0*nframes; // you may want to rotate by half a frame here

There are several examples of this on the forums.