rotation problem

Non-platform specific questions.

rotation problem

Postby BogdansB » Sat Dec 01, 2012 8:54 am

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?
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: rotation problem

Postby skydereign » Sat Dec 01, 2012 9:04 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: rotation problem

Postby BogdansB » Sat Dec 01, 2012 9:12 am

yes please
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: rotation problem

Postby skydereign » Sat Dec 01, 2012 9:19 am

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;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: rotation problem

Postby BogdansB » Sat Dec 01, 2012 9:30 am

right :D thanks it works
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: rotation problem

Postby Slayer40008 » Sat Jan 04, 2014 5:53 am

]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.
Slayer40008
 
Posts: 1
Joined: Fri Aug 02, 2013 12:20 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron