diff options
author | quou <quou@disroot.org> | 2024-10-04 19:56:50 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-10-04 19:56:50 +1000 |
commit | 6cab1d56ad2b29a2556090f1f0ce7e2b72d5460a (patch) | |
tree | 862eee5b2390a1fbc07310d168d3948ca2723656 | |
parent | e4b0008f5ca0c00fa3a51f08968a0154a3686c4a (diff) |
Improve physics stability
-rw-r--r-- | physics.c | 40 |
1 files changed, 26 insertions, 14 deletions
@@ -148,14 +148,20 @@ void update_body( if (ramp) goto do_x; ittiles({ if (tc == 1) { - if (*vy > 0) { - *y = tr.y - (r->y + r->h); - *vy = 0; - *grounded = 0; - } else if (*vy < 0) { - *y = (tr.y + tr.h) - r->y; - *vy = 0; - *headbutted = 1; + int to = *y + r->y + r->h - tr.y; + int bo = tr.y + tr.h - (r->y + *y); + if (to < bo) { + if (*vy > 0) { + *y = tr.y - (r->y + r->h); + *vy = 0; + *grounded = 0; + } + } else { + if (*vy < 0) { + *y = (tr.y + tr.h) - r->y; + *vy = 0; + *headbutted = 1; + } } } }); @@ -188,12 +194,18 @@ do_x: } ittiles({ if (tc == 1) { - if (*vx > 0) { - *x = tr.x - (r->x + r->w); - *vx = 0; - } else if (*vx < 0) { - *x = (tr.x + tr.w) - r->x; - *vx = 0; + int le = *x + r->x + r->w - tr.x; + int ri = tr.x + tr.w - (r->x + *x); + if (le < ri) { + if (*vx > 0) { + *x = tr.x - (r->x + r->w); + *vx = 0; + } + } else { + if (*vx < 0) { + *x = (tr.x + tr.w) - r->x; + *vx = 0; + } } } }); |