stop lerping on collision with vertical wall

This commit is contained in:
nek0 2021-01-19 12:50:15 +01:00
parent 0b03c306c3
commit fe947c8ba5
3 changed files with 28 additions and 27 deletions

View file

@ -45,7 +45,7 @@ class (Show c, Mass c) => Collidible c where
m2p2 = V2 m2b1x m2b2y
m2p3 = m2b2
m2p4 = V2 m2b2x m2b1y
quad1 = map (p1 + d1 +) [m1p1, m1p2, m1p3, m1p4]
quad1 = map (p1 +) [m1p1, m1p2, m1p3, m1p4]
g1 = (m2p1, m2p2)
g2 = (m2p2, m2p3)
g3 = (m2p3, m2p4)
@ -141,40 +141,40 @@ elasticCollision damping mo1 mo2 (Collision ddt direction) =
then (V2 (-v1x) v1y)
else (V2 v1x (-v1y))
else (V2 v1x' v1y')
bx = if dx <= 0
bx = if dx < 0
then
if abs dx >= abs m1x1 + abs m2x2 &&
if abs dx > abs m1x1 + abs m2x2 &&
(if dy > 0
then abs dy >= abs m1y2 + abs m2y1
else abs dy >= abs m1y1 + abs m2y2
then abs dy > abs m1y2 + abs m2y1
else abs dy > abs m1y1 + abs m2y2
)
then 0
else (abs m1x1 + abs m2x2) - abs dx + 1
else (abs m1x1 + abs m2x2) - abs dx
else
if abs dx >= abs m1x2 + abs m2x1 &&
if abs dx > abs m1x2 + abs m2x1 &&
(if dy > 0
then abs dy >= abs m1y2 + abs m2y1
else abs dy >= abs m1y1 + abs m2y2
then abs dy > abs m1y2 + abs m2y1
else abs dy > abs m1y1 + abs m2y2
)
then 0
else -((abs m1x2 + abs m2x1) - abs dx + 1)
by = if dy <= 0
else -((abs m1x2 + abs m2x1) - abs dx)
by = if dy < 0
then
if abs dy >= abs m1y1 + abs m2y2 &&
if abs dy > abs m1y1 + abs m2y2 &&
(if dx > 0
then abs dx >= abs m1x2 + abs m2x1
else abs dx >= abs m1x1 + abs m2x2
then abs dx > abs m1x2 + abs m2x1
else abs dx > abs m1x1 + abs m2x2
)
then 0
else (abs m1y1 + abs m2y2) - abs dy + 1
else (abs m1y1 + abs m2y2) - abs dy
else
if abs dy >= abs m1y2 + abs m2y1 &&
if abs dy > abs m1y2 + abs m2y1 &&
(if dx > 0
then abs dx >= abs m1x2 + abs m2x1
else abs dx >= abs m1x1 + abs m2x2
then abs dx > abs m1x2 + abs m2x1
else abs dx > abs m1x1 + abs m2x2
)
then 0
else -((abs m1y2 + abs m2y1) - abs dy + 1)
else -((abs m1y2 + abs m2y1) - abs dy)
in
(velocityUpdater
((positionUpdater mo1)

View file

@ -59,6 +59,4 @@ class Mass m where
move dt m =
let dpos@(V2 dx dy) = (dt *) <$> velocity m
in
if dy < 0 && abs dy < 1
then (positionUpdater m) (position m + (V2 dx 0))
else (positionUpdater m) (position m + dpos)
(positionUpdater m) (position m + dpos)

View file

@ -89,7 +89,6 @@ instance Actor Pituicat where
finalCat = physCat
{ pcMoveVel =
lerp (min 0.95 (59 * dt)) (pcMoveVel physCat) (pcTMoveVel physCat)
-- pcTMoveVel physCat
}
in
(A.log Debug (
@ -152,14 +151,18 @@ instance Collidible Pituicat where
fromString (show other))
(
let ncat = (elasticCollision 0.3 cat other collr)
(V2 dx dy) = (ddt *) <$> (
nvel@(V2 dx dy) =
velocity ncat *
if dirx /= 0
if dirx == 0
then V2 0 1
else V2 1 1
)
grounded = (dy * ddt) <= 0 && (dy * ddt) > (-2) && diry == 0
in
ncat
{ pcGrounded = abs dy < 2
{ pcGrounded = grounded
, pcMoveVel = pcMoveVel ncat *
if dirx == 0
then V2 0 1
else V2 1 1
}
)