Round coordinates in collision detection
This fixes an issue where the player could get stuck to an edge when being aligned to the pixel grid due to the rounded coordinate being outside an invalid tile but the truncated position being inside. Also we should be doing it anyway.
This commit is contained in:
parent
6d01f8cc3f
commit
77725a5ce4
11
game/main.c
11
game/main.c
@ -409,11 +409,14 @@ static void entityupdate(gamestate_t *state, entity_t *e, double dt)
|
||||
const dvec_t pfb
|
||||
= { .x = nextx + e->fbox.off.x, .y = nexty + e->fbox.off.y };
|
||||
bool valid = true;
|
||||
valid &= tilepassable(state->map, pfb.x, pfb.y);
|
||||
valid &= tilepassable(state->map, pfb.x + e->fbox.ext.x, pfb.y);
|
||||
valid &= tilepassable(state->map, pfb.x, pfb.y + e->fbox.ext.y);
|
||||
valid &= tilepassable(state->map, (int)rint(pfb.x), (int)rint(pfb.y));
|
||||
valid &= tilepassable(
|
||||
state->map, pfb.x + e->fbox.ext.x, pfb.y + e->fbox.ext.y);
|
||||
state->map, (int)rint(pfb.x + e->fbox.ext.x), (int)rint(pfb.y));
|
||||
valid &= tilepassable(
|
||||
state->map, (int)rint(pfb.x), (int)rint(pfb.y + e->fbox.ext.y));
|
||||
valid &= tilepassable(
|
||||
state->map, (int)rint(pfb.x + e->fbox.ext.x),
|
||||
(int)rint(pfb.y + e->fbox.ext.y));
|
||||
if (valid) {
|
||||
e->pos.x = nextx;
|
||||
e->pos.y = nexty;
|
||||
|
Loading…
x
Reference in New Issue
Block a user