Page 1 of 1

rotation problem

PostPosted: Sat Dec 01, 2012 8:54 am
by BogdansB
HELLO,

when i use the code

Code: Select all
angle=direction(x, y, enemy.x, enemy.y); //test angle
animpos=angle/360*nframes;




to rotate my sprites , the player "flys" to the enemy , its like move to, but he rotates... i tried to fix it by chaging the angle with another variable , but than he doesnt rotate... how can i fix it?

Re: rotation problem

PostPosted: Sat Dec 01, 2012 9:04 am
by skydereign
Changing both lines' angle to your newly created one should work. I can post an example of it working if you still can't get it to work.

Re: rotation problem

PostPosted: Sat Dec 01, 2012 9:12 am
by BogdansB
yes please

Re: rotation problem

PostPosted: Sat Dec 01, 2012 9:19 am
by skydereign
In fact, since aside from rotating you don't need the variable you should just do this. That way you never change the angle of the enemy.
Code: Select all
animpos = direction(x, y, enemy.x, enemy.y)/360*nframes;

Re: rotation problem

PostPosted: Sat Dec 01, 2012 9:30 am
by BogdansB
right :D thanks it works

Re: rotation problem

PostPosted: Sat Jan 04, 2014 5:53 am
by Slayer40008
]If you would like to center your rotation, you could use the "round" feature and a simple IF statement to offset the final frame of your rotation.

Example:
Code: Select all
int MyDirection;
angle = direction(xscreen, yscreen, xmouse, ymouse);//direction toward mouse position//
MyDirection=round(angle/360*nframes);
if (MyDirection=='max frame')  //*'max frame'=last frame # of animation sequence, example: 16 frame animation, 'max frame'=16*//
MyDirection=0;
animpos=MyDirection;

This will center your actors rotation for each frame. For instance on a 16 frame rotation, you actor will face directly right from approx. 349.5° to approx. 11.4° instead of 0° to 22.5°.
I'm sure there is an easier way but this works great for all my games.

Hope this helps.