/** * Converts this vector to a unit vector (a vector with length of 1). * * @return the same vector */ public Vector normalize() { double length = length(); x /= length; y /= length; z /= length; return this; }
@Override public SpellResult start(CastContext context) { if (movementSpread > 0) { double entitySpeed = context.getMage().getVelocity().lengthSquared(); if (entitySpeed > 0) { double movementAmount = Math.min(1.0, entitySpeed / (movementSpread * movementSpread)); spread += (movementAmount * maxMovementSpread); if (context.getMage().getDebugLevel() >= 3) { context.getMage().sendDebugMessage(ChatColor.DARK_RED + " Applying spread of " + ChatColor.RED + spread + ChatColor.DARK_RED + " from speed of " + ChatColor.GOLD + context.getMage().getVelocity().length()); } } } return super.start(context); }
private double distanceTo(Entity entity) { return RayUtil.getRayBetween(location, entity.getLocation()).length(); }
@Override public void setDirection(Vector vector) { setVelocity(vector.normalize().multiply(velocity.length())); }
/** * Converts this vector to a unit vector (a vector with length of 1). * * @return the same vector */ public Vector normalize() { double length = length(); x /= length; y /= length; z /= length; return this; }
private static Vector clip(double max, Vector vector) { if (vector.length() > max) { return vector.normalize().multiply(max); } return vector; }
public static Vector rotateVectorAroundVector(final Vector axis, final Vector rotator, final double degrees) { final double angle = Math.toRadians(degrees); Vector rotation = axis.clone(); final Vector rotate = rotator.clone(); rotation = rotation.normalize(); final Vector thirdaxis = rotation.crossProduct(rotate).normalize().multiply(rotate.length()); return rotate.multiply(Math.cos(angle)).add(thirdaxis.multiply(Math.sin(angle))); }
public static double getDistanceFromLine(final Vector line, final Location pointonline, final Location point) { final Vector AP = new Vector(); double Ax, Ay, Az; Ax = pointonline.getX(); Ay = pointonline.getY(); Az = pointonline.getZ(); double Px, Py, Pz; Px = point.getX(); Py = point.getY(); Pz = point.getZ(); AP.setX(Px - Ax); AP.setY(Py - Ay); AP.setZ(Pz - Az); return (AP.crossProduct(line).length()) / (line.length()); }
@EventHandler(priority = EventPriority.NORMAL) public void onPlayerMove(PlayerMoveEvent event) { final Player player = event.getPlayer(); final FPlayer fPlayer = plugin.pl.getPlayer(player); if (!fPlayer.isOrbiting()) { return; } if (player.getVelocity().length() < fPlayer.orbitStrength() * (2.0 / 3.0)) { player.setVelocity(new Vector(0, fPlayer.orbitStrength(), 0)); } }
@Override public void onRun() { Location location = getLocation(); Location target = getTarget(); if (target == null) { cancel(); return; } Vector link = target.toVector().subtract(location.toVector()); float length = (float) link.length(); float pitch = (float) (4 * height / Math.pow(length, 2)); for (int i = 0; i < particles; i++) { Vector v = link.clone().normalize().multiply((float) length * i / particles); float x = ((float) i / particles) * length - length / 2; float y = (float) (-pitch * Math.pow(x, 2) + height); location.add(v).add(0, y, 0); display(particle, location); location.subtract(0, y, 0).subtract(v); step++; } }
/** * Knocks a target back from damage received (for hacked-in damage applications when required by config). */ public void knockback(LivingEntity entity) { Vector relative = entity.getLocation().toVector().subtract(getLivingEntity().getLocation().toVector()); relative = relative.normalize(); relative.setY(0.75); relative.multiply(0.5 / Math.max(1.0, entity.getVelocity().length())); entity.setVelocity(entity.getVelocity().multiply(0.25).add(relative)); if (SentinelPlugin.debugMe) { debug("applied knockback velocity adder of " + relative); } } }
@EventHandler public void onProjectileLaunch(ProjectileLaunchEvent e){ Projectile projectile = e.getEntity(); //Getting the projectile ProjectileSource shooter = projectile.getShooter(); //Getting the shooter if(shooter instanceof Player){ //If the shooter was a player Player player = (Player) shooter; if(!isEnabled(player.getWorld())) return; //If this module is enabled in this world debug("Making projectile go straight", player); //Here we get a unit vector of the direction the player is looking in and multiply it by the projectile's vector's magnitude //We then assign this to the projectile as its new velocity projectile.setVelocity(player.getLocation().getDirection().normalize().multiply(projectile.getVelocity().length())); } } }
private void playRotationAnimation() { final double length = new Vector(this.hitBox.motX, this.hitBox.motY, this.hitBox.motZ).length(); EulerAngle angle = null; final EulerAngle a = this.getHeadPose(); if (length > 1.0) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.5, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.5, 0, 0); } } else if (length > 0.1) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.25, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.25, 0, 0); } } else if (length > 0.08) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.025, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.025, 0, 0); } } if (angle != null) { this.setHeadPose(angle); } }
private void playRotationAnimation() { final double length = new Vector(this.hitBox.motX, this.hitBox.motY, this.hitBox.motZ).length(); EulerAngle angle = null; final EulerAngle a = this.getHeadPose(); if (length > 1.0) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.5, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.5, 0, 0); } } else if (length > 0.1) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.25, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.25, 0, 0); } } else if (length > 0.08) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.025, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.025, 0, 0); } } if (angle != null) { this.setHeadPose(angle); } }
@Override public void run() { if (!target.isValid() || projectile.isDead() || !projectile.isValid() || ticks-- <= 0) { cancel(); return; } Vector origVel = projectile.getVelocity(); double v = origVel.length(); Vector rel = target.getEyeLocation().toVector().subtract(projectile.getLocation().toVector()).normalize().multiply(v); rel.multiply(velFactor).add(origVel.multiply(1 - velFactor)); projectile.setVelocity(rel); if (projectile instanceof Fireball) { ((Fireball) projectile).setDirection(rel.normalize()); } } }.runTaskTimer(RPGItems.plugin, 1, 0);
private void playRotationAnimation() { final double length = new Vector(this.hitBox.motX, this.hitBox.motY, this.hitBox.motZ).length(); EulerAngle angle = null; final EulerAngle a = this.getHeadPose(); if (length > 1.0) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.5, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.5, 0, 0); } } else if (length > 0.1) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.25, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.25, 0, 0); } } else if (length > 0.08) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.025, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.025, 0, 0); } } if (angle != null) { this.setHeadPose(angle); } }
private void playRotationAnimation() { final double length = new Vector(this.hitBox.motX, this.hitBox.motY, this.hitBox.motZ).length(); EulerAngle angle = null; final EulerAngle a = this.getHeadPose(); if (length > 1.0) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.5, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.5, 0, 0); } } else if (length > 0.1) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.25, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.25, 0, 0); } } else if (length > 0.08) { if (this.revertAnimation) { angle = new EulerAngle(a.getX() - 0.025, 0, 0); } else { angle = new EulerAngle(a.getX() + 0.025, 0, 0); } } if (angle != null) { this.setHeadPose(angle); } }
@EventHandler public void onHorizontalCollision(final HorizontalVelocityChangeEvent e) { if (e.getEntity() instanceof LivingEntity) { if (e.getEntity().getEntityId() != e.getInstigator().getEntityId()) { final double minimumDistance = this.plugin.getConfig().getDouble("Properties.HorizontalCollisionPhysics.WallDamageMinimumDistance"); final double maxDamage = this.plugin.getConfig().getDouble("Properties.HorizontalCollisionPhysics.WallDamageCap"); final double damage = ((e.getDistanceTraveled() - minimumDistance) < 0 ? 0 : e.getDistanceTraveled() - minimumDistance) / (e.getDifference().length()); if (damage > 0) { if (damage <= maxDamage) { DamageHandler.damageEntity(e.getEntity(), damage, e.getAbility()); } else { DamageHandler.damageEntity(e.getEntity(), maxDamage, e.getAbility()); } } } } }