You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current movement uses integer calculations for coords and increments. This if fine for Horiz or Vert movement, but when moving diagonally it moves much faster. E.g. for DX=1 and DY=1, if we move Horiz or Vert (only) X or Y are incremented by 1, speed is 1 pixel per time unit. But if we move diagonally, X and Y are simultaneously incremented by DX=1 and DY=1, and the speed is then 1.41 pixels per time unit, which is 41% faster.
This can be avoided if we keep the movement coordinates and increments as 16-bit fixed point values (8 bit integer + 8 bit decimal), and also increments according to directions are adjusted for the diagonal moves (e.g. DX = 1 if moving Horiz, but DX = DY = 0.71 if moving diagonally).
Fixed Point math should be done in base 256 for best precision.
Update:
Use Fixed Point coordinates for hero movement.
Add DX_BOTH and DY_BOTH increments, used when moving in H and V direction simultaneously. Calculate as DYsin(W) and DXcos(W), being W = arctan(DY/DX). Precalculate in DATAGEN and generate FP fractional values ready to use (no trig calculations in realtime!)
The text was updated successfully, but these errors were encountered:
jorgegv
changed the title
hero: calculate movements with fractional fixed point math coordinates
hero: calculate movements with fractional fixed point coordinates
Aug 23, 2022
The current movement uses integer calculations for coords and increments. This if fine for Horiz or Vert movement, but when moving diagonally it moves much faster. E.g. for DX=1 and DY=1, if we move Horiz or Vert (only) X or Y are incremented by 1, speed is 1 pixel per time unit. But if we move diagonally, X and Y are simultaneously incremented by DX=1 and DY=1, and the speed is then 1.41 pixels per time unit, which is 41% faster.
This can be avoided if we keep the movement coordinates and increments as 16-bit fixed point values (8 bit integer + 8 bit decimal), and also increments according to directions are adjusted for the diagonal moves (e.g. DX = 1 if moving Horiz, but DX = DY = 0.71 if moving diagonally).
Fixed Point math should be done in base 256 for best precision.
Update:
The text was updated successfully, but these errors were encountered: