Skip to content

Instantly share code, notes, and snippets.

@izzyaxel
Created September 4, 2016 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izzyaxel/ca1483e034914dc43ddc2798be330ef2 to your computer and use it in GitHub Desktop.
Save izzyaxel/ca1483e034914dc43ddc2798be330ef2 to your computer and use it in GitHub Desktop.
if(jump)
{
int xDir = 0, zDir = 0;
if(forward)
{
zDir += 1;
}
if(back)
{
zDir -= 1;
}
if(left)
{
xDir += 1;
}
if(right)
{
xDir -= 1;
}
double yaw = (player.rotationYaw / 180) * Math.PI;
player.motionX += ((xDir * Math.cos(yaw)) - (zDir * Math.sin(yaw))) * 0.06;
player.motionZ += ((xDir * Math.sin(yaw)) + (zDir * Math.cos(yaw))) * 0.06;
double maxVert = 0.4, maxHoriz = 0.6;
if(player.motionX > maxHoriz)
{
player.motionX = maxHoriz;
}
if(player.motionZ > maxHoriz)
{
player.motionZ = maxHoriz;
}
if(player.motionX < -maxHoriz)
{
player.motionX = -maxHoriz;
}
if(player.motionZ < -maxHoriz)
{
player.motionZ = -maxHoriz;
}
if(player.onGround)
{
player.motionY = 0.3;
}
else
{
player.motionY += 0.115;
}
if(player.motionY > maxVert)
{
player.motionY = maxVert;
}
player.fallDistance = 0.0f;
player.velocityChanged = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment