Advertisement

how do I make my player rotate in right or left direction to stay away from obstacle in 2d game...please help me out

Started by April 09, 2022 08:08 AM
1 comment, last by Programmer71 2 years, 5 months ago

i wanna make a 2d game in unity where player can rotate in right or left direction for android ..i have been looking for tutorials but it didn't helped me out..

any help would be appreciated. .thankyou

Well, I think a little bit of math might help :

float rad=45*DEGTORAD; // convert degree to radians, 45 is for example you can put any angle

float dx=sin(rad);

float dy = cos(rad);

// player moves along the direction of dx,dy vector , define posx , psy as initial position and update them

posx+=dx;

posy+=dy;

// there you go

This topic is closed to new replies.

Advertisement