Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate the shortest way to rotate, right or left?

Tags:

javascript

Im making a simple computerplayer to my simple 2d action game. it suppose to turn towards me and shoot, but i cant figure out how to calc the shortest path... should it turn left of right if it want to shoot and kill me :P ?

Ive got two angles: cpu_facing (direction the cpu is facing) and player_degree (the angle calculated when cpu is in the center).

(im working with degrees, dont like radian :P)

Anyone done this in javascript?

like image 212
Jason94 Avatar asked Dec 06 '10 20:12

Jason94


1 Answers

(cpu_facing-player_degree+360)%360>180
  • false: turn in the negative direction
  • true: turn in the positive direction
like image 178
thejh Avatar answered Sep 17 '22 17:09

thejh