
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 0.77 KB | hits: 8 | expires: Never
rotate player to face planet
double rotation = Math.toDegrees(Math.atan2(currentPlanet.pos[1]-currentPlayer.pos[1], currentPlanet.pos[0]-currentPlayer.pos[0]));
if(rotation < 0)
{
rotation += 360;
}
if(currentPlayer.rotation < rotation)
{
currentPlayer.rotation += 0.15*delta;
}
if(currentPlayer.rotation > rotation)
{
currentPlayer.rotation -= 0.15*delta;
}
/* returns angle x represented in range -180.0 ... 180.0 */
double clampAngle(double x) {
return (x%360.0+360.0+180.0)%360.0-180.0;
}
double rotation = Math.toDegrees(Math.atan2(currentPlanet.pos[1]-currentPlayer.pos[1], currentPlanet.pos[0]-currentPlayer.pos[0]));
double diff = ((rotation-currentPlayer.rotation)%360.0+360.0+180.0)%360.0-180.0;
if(diff>0)
turn right
else
turn left