Page 1 of 1

Changine missle direction angle?

PostPosted: Wed Aug 04, 2010 7:55 pm
by Hblade
Okay, I have a missile and it fails to change its animpos :( Its a homing missile, I have the homing part down pact but its the changing the animation is the problem >.>

How would I have it change? Its an 8 frame missile, here:
missle.gif
missle.gif (1 KiB) Viewed 813 times


I need it to change as if it's really homing in on the player :o

Re: Changine missle direction angle?

PostPosted: Wed Aug 04, 2010 8:18 pm
by savvy
use this:
Code: Select all
angle=direction(x,y,-target-.x,-target-.y);animpos=(angle/360)*-amount of frames(8)-;
change the amount of frames to 8 in your case, and the target to what its homing in on.

Re: Changine missle direction angle?

PostPosted: Wed Aug 04, 2010 8:35 pm
by Hblade
Thanks savvy :D!

Re: Changine missle direction angle?

PostPosted: Wed Aug 04, 2010 9:27 pm
by savvy
np

Re: Changine missle direction angle?

PostPosted: Thu Aug 05, 2010 2:00 pm
by Hblade
The variable called "nframes" will tell you how much frames is in 1 animation :D so use -nframes instead of 8 :3

Re: Changine missle direction angle?

PostPosted: Thu Aug 05, 2010 2:06 pm
by DilloDude
If you already know the number of frames (which you should, considering you made the animation) you can just use the number of degrees.
Code: Select all
animpos = angle / 45;

This only uses one division, so is more efficient.
Even better, you can do a multiplacation - take the angle - in this case 45 - and divide 1 by it. 1 / 45 = 0.022222222222222222222222222222222
That would be
Code: Select all
animpos = angle * 0.022222222222222222222222222222222;

This is not quite such a nice number for it, so you may want to divide anyway. But when it becomes a nice compact number, such as .1 or .025 or whatever, you can multiply.