Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-260600

Mobs are more affected by speed modifiers than they should be

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.19.3, 1.20.6, 24w18a
    • None
    • Community Consensus
    • Entities, Mob behaviour
    • Normal
    • Platform

      Mobs that are under the influence of speed modifiers, such as potions, are more affected by them than they should be.

      The apparent reason in the game's code shows in the movementInputToVelocity function in Entity, called by applyMovementInput in LivingEntity.

      public Vec3d applyMovementInput(Vec3d movementInput, float slipperiness) {
              this.updateVelocity(this.getMovementSpeed(slipperiness), movementInput);
      
              ...
      
      public void updateVelocity(float speed, Vec3d movementInput) {
              Vec3d vec3d = Entity.movementInputToVelocity(movementInput, speed, this.getYaw());
              this.setVelocity(this.getVelocity().add(vec3d));
      }
      private static Vec3d movementInputToVelocity(Vec3d movementInput, float speed, float yaw) {
              double d = movementInput.lengthSquared();
              if (d < 1.0E-7) {
                  return Vec3d.ZERO;
              }
              Vec3d vec3d = (d > 1.0 ? movementInput.normalize() : movementInput).multiply(speed);
              float f = MathHelper.sin(yaw * ((float)Math.PI / 180));
              float g = MathHelper.cos(yaw * ((float)Math.PI / 180));
              return new Vec3d(vec3d.x * (double)g - vec3d.z * (double)f, vec3d.y, vec3d.z * (double)g + vec3d.x * (double)f);
      }

      Each mob is given a movementInput forward value of whatever its speed attribute is, while for players it is usually 1. Since the speed attribute is multiplied by this value in applyMovementInput, this means this means that what is added to the mob's velocity is its movement attribute squared. Modifiers affect movementInput, so a 2x multiplier to the mob's speed attribute will cause a 4x increase in speed.

      I made a video to demonstrate this behavior in vanilla 1.19.3. On the left is a normal zombie, in the middle is a zombie with slowness III (-45% speed), and on the right is a zombie with swiftness V (+100% speed). The swiftness zombie should reach the villager by the time the normal zombie reaches the halfway point, but the normal zombie only reaches about a quarter of the way through. The same happens for the slow zombie. The normal zombie should reach the villager when the slow zombie is a little past the halfway point, but instead the slow zombie makes it about a third of the way.

        1. 2024-05-07_19-32-18.mp4
          9.40 MB
        2. image-2024-06-10-12-18-19-514.png
          image-2024-06-10-12-18-19-514.png
          1.43 MB
        3. MC-206600 Testing.zip
          1.05 MB
        4. speed_comparison.mp4
          6.45 MB
        5. zombie_speed_test.zip
          1.30 MB

            Unassigned Unassigned
            merfmango merfmango
            Votes:
            5 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              CHK: