🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

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
1 comment, last by Programmer71 2 years, 2 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

Advertisement

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