]> git.lizzy.rs Git - minetest.git/commit
Fix player coordinate rounding in collisionMoveSimple() (#6197)
authorJens Rottmann <30634967+JRottm@users.noreply.github.com>
Fri, 4 Aug 2017 19:48:32 +0000 (21:48 +0200)
committersfan5 <sfan5@live.de>
Sat, 5 Aug 2017 10:38:11 +0000 (12:38 +0200)
commit0c893ea1232c96f43d6934bdce8f954ae05b1203
tree4b3e5812aafb9836537108ff6c910aa0c2472c77
parente63df5ce80eb1a0955e04f75ce8f72f119dc5f3c
Fix player coordinate rounding in collisionMoveSimple() (#6197)

To determine the area (nodes) where a player movement took place
collisionMoveSimple() first took the old/new player coordinates and rounded
them to integers, then added the player character's collision box and
implicitely rounded the result. This has 2 problems:

Rounding the position and the box seperately, then adding the resulting
integers means you get twice the rounding error. And implicit rounding
always rounds towards 0.0, unlike floatToInt(), which rounds towards the
closest integer.

Previous (simplified) behavior: round(pos)+(int)box, for example player at
Y=0.9, body is 1.75m high: round(0.9)+(int)1.75 = 1+1 = 2.
==> A character's height of 1.75m always got rounded down to 1m, its width
of +/-0.3 even became 0.

Fixed by adding the floats first, then rounding properly: round(pos+box) =
round(0.9+1.75) = round(2.65) = 3.
src/collision.cpp