Skip to content

Instantly share code, notes, and snippets.

@S4WA
Last active March 13, 2019 09:16
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 S4WA/7ce7630e07162c2b121bb84a9cca59f6 to your computer and use it in GitHub Desktop.
Save S4WA/7ce7630e07162c2b121bb84a9cca59f6 to your computer and use it in GitHub Desktop.
velocity
@EventHandler
private void onVelocity(PlayerVelocityEvent event) {
if (event.getPlayer().getLastDamageCause().getCause() != EntityDamageEvent.DamageCause.ENTITY_ATTACK) return;
Player damaged = event.getPlayer();
Vector vector = damaged.getVelocity();
vector.normalize();
if (!damaged.isSprinting()) {
vector = new Vector(vector.getX() * this.horizontal, 1.0D * this.vertical, vector.getZ() * this.horizontal);
} else {
vector = new Vector(vector.getX() * this.sprintHorizontal, vector.getY() * this.sprintVertical, vector.getZ() * this.sprintHorizontal);
}
event.setVelocity(vector);
}
private double vertical = 0.35D, horizontal = 0.35D, sprintVertical = 0.55D, sprintHorizontal = 0.45D;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment