news.volyx.in

Aztec monks with 1/55 HP no longer die when picking up or dropping a relic (reddit.com)

525 points by danso · 1236 days ago · 208 comments on HN

Article summary

The article discusses a bug in a game where Aztec monks with low health would die when picking up or dropping a relic due to a floating point rounding error. The error occurred when the unit's health was scaled proportionally based on its old and new maximum health using 32-bit floating point math. The bug has been fixed, but the discussion revolves around the best approach to avoid similar issues in the future. The use of floating point numbers in game development is a common source of errors and requires careful consideration.

Main themes

  • floating point errors
  • game development
  • numeric representation
  • rationals vs floats
  • health scaling
  • error mitigation

What commenters say

  • Using rationals instead of floats can avoid floating point rounding errors, but may introduce exponential blowup in storage and precision.
  • Storing health as a percentage of the maximum health can simplify calculations and avoid scaling issues, but may make other calculations more expensive and complicated.
  • Changing the threshold for death from 1 HP to 0 HP can avoid the problem of units dying due to floating point errors, but may violate conventions and cause other issues.
  • Using integers or fixed-point numbers can provide a more precise and reliable representation of health, but may not be suitable for all game development scenarios.
  • The choice of numeric representation depends on the specific requirements and constraints of the game, and there is no one-size-fits-all solution.
  • Strategically placed rounding steps can help mitigate the effects of floating point errors, but may not eliminate them entirely.