The best way to do this is with a single animation containing however many frames you want coming from the angle 0 degree to 360 degree minus one frame. Angle 0/360 starts pointing Right, so your turret would be pointing right, then up, then left, then down, then back right (Minus one frame, we don't need the same position twice). After you have made you animation, you can have this little code in the Draw Actor event to make it point to your cursor, in this example it will be the mouse itself:
- Code: Select all
animpos=(direction(x,y,(xmouse-view.width/2),(ymouse-view.height/2))/360)*nframes;
if you want it to follow an actor, this script would be used instead, just replace actor with the actor you want it to point to:
- Code: Select all
animpos=(direction(x,y,actor.x,actor.y)/360)*nframes;
What the script does:
Animpos is the current animation frame
direction(x1,y1,x2,y2) gets an angle from 0 to 359
We then divide that angle by 360 so the value ranges from 0 to 1 (Well almost 1!)
Multiply this by the numbers of frame and your animpos will now correspond with your angle!
since we arranged the animation with the angle data, we don't need to change anything else to our angle value
I hope this helps!