Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.77 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. rotate player to face planet
  2. double rotation = Math.toDegrees(Math.atan2(currentPlanet.pos[1]-currentPlayer.pos[1], currentPlanet.pos[0]-currentPlayer.pos[0]));
  3. if(rotation < 0)
  4. {
  5.     rotation += 360;
  6. }
  7.  
  8. if(currentPlayer.rotation < rotation)
  9. {
  10.     currentPlayer.rotation += 0.15*delta;
  11. }
  12.  
  13. if(currentPlayer.rotation > rotation)
  14. {
  15.     currentPlayer.rotation -= 0.15*delta;
  16. }
  17.        
  18. /* returns angle x represented in range -180.0 ... 180.0 */
  19. double clampAngle(double x) {
  20.     return (x%360.0+360.0+180.0)%360.0-180.0;
  21. }
  22.        
  23. double rotation = Math.toDegrees(Math.atan2(currentPlanet.pos[1]-currentPlayer.pos[1], currentPlanet.pos[0]-currentPlayer.pos[0]));
  24. double diff =  ((rotation-currentPlayer.rotation)%360.0+360.0+180.0)%360.0-180.0;  
  25.  
  26. if(diff>0)
  27.     turn right
  28. else
  29.     turn left