entity: truncate move delta to [0, 1]

This commit is contained in:
Edgaru089 2022-02-05 19:24:53 +08:00
parent 0e4e17ced7
commit 9122954e62

View File

@ -25,6 +25,13 @@ const MoveEps = 1e-7
// It does not change anything in e.
func (e *Entity) move(delta itype.Vec3d, w *world.World) (finDelta itype.Vec3d, finVelocity itype.Vec3d, onGround bool) {
// Truncate the delta to [0, 1]
for i := 0; i < len(delta); i++ {
if math.Abs(delta[i]) > 1 {
delta[i] /= math.Abs(delta[i])
}
}
// Get the hitboxes and the blocks region covering it
hb := e.WorldHitbox()
hbmin, hbmax := itype.Vec3d{1000000000, 1000000000, 1000000000}, itype.Vec3d{-1000000000, -1000000000, -1000000000}