aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-10-04 19:56:50 +1000
committerquou <quou@disroot.org>2024-10-04 19:56:50 +1000
commit6cab1d56ad2b29a2556090f1f0ce7e2b72d5460a (patch)
tree862eee5b2390a1fbc07310d168d3948ca2723656
parente4b0008f5ca0c00fa3a51f08968a0154a3686c4a (diff)
Improve physics stability
-rw-r--r--physics.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/physics.c b/physics.c
index 332d292..a9bcc59 100644
--- a/physics.c
+++ b/physics.c
@@ -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;
+ }
}
}
});