Skip to content

Instantly share code, notes, and snippets.

@dalbothek
Forked from md-5/Bot.java
Created July 19, 2012 10:15
Show Gist options
  • Save dalbothek/3142874 to your computer and use it in GitHub Desktop.
Save dalbothek/3142874 to your computer and use it in GitHub Desktop.
REl move code
/**
* Moves the specified amount forwards and left in the current direction
* (calculated based on current yaw)
*
* @param forward, double sideways how far to move
* @param left how far to the left to move
*/
public void moveRelative(double forward, double left) {
final float yaw = getLocation().getYaw();
final double xToMove = - forward * Math.sin(yaw) + left * Math.cos(yaw);
final double zTomove = forward * Math.cos(yaw) + left * Math.sin(yaw);
getLocation().setX(getLocation().getX() + xToMove);
getLocation().setZ(getLocation().getZ() + zTomove);
getLocation().setYaw(Math.atan2(-xToMove, zToMove));
//
sendLocationUpdate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment