stop lerping on collision with vertical wall
This commit is contained in:
parent
0b03c306c3
commit
fe947c8ba5
|
@ -45,7 +45,7 @@ class (Show c, Mass c) => Collidible c where
|
||||||
m2p2 = V2 m2b1x m2b2y
|
m2p2 = V2 m2b1x m2b2y
|
||||||
m2p3 = m2b2
|
m2p3 = m2b2
|
||||||
m2p4 = V2 m2b2x m2b1y
|
m2p4 = V2 m2b2x m2b1y
|
||||||
quad1 = map (p1 + d1 +) [m1p1, m1p2, m1p3, m1p4]
|
quad1 = map (p1 +) [m1p1, m1p2, m1p3, m1p4]
|
||||||
g1 = (m2p1, m2p2)
|
g1 = (m2p1, m2p2)
|
||||||
g2 = (m2p2, m2p3)
|
g2 = (m2p2, m2p3)
|
||||||
g3 = (m2p3, m2p4)
|
g3 = (m2p3, m2p4)
|
||||||
|
@ -141,40 +141,40 @@ elasticCollision damping mo1 mo2 (Collision ddt direction) =
|
||||||
then (V2 (-v1x) v1y)
|
then (V2 (-v1x) v1y)
|
||||||
else (V2 v1x (-v1y))
|
else (V2 v1x (-v1y))
|
||||||
else (V2 v1x' v1y')
|
else (V2 v1x' v1y')
|
||||||
bx = if dx <= 0
|
bx = if dx < 0
|
||||||
then
|
then
|
||||||
if abs dx >= abs m1x1 + abs m2x2 &&
|
if abs dx > abs m1x1 + abs m2x2 &&
|
||||||
(if dy > 0
|
(if dy > 0
|
||||||
then abs dy >= abs m1y2 + abs m2y1
|
then abs dy > abs m1y2 + abs m2y1
|
||||||
else abs dy >= abs m1y1 + abs m2y2
|
else abs dy > abs m1y1 + abs m2y2
|
||||||
)
|
)
|
||||||
then 0
|
then 0
|
||||||
else (abs m1x1 + abs m2x2) - abs dx + 1
|
else (abs m1x1 + abs m2x2) - abs dx
|
||||||
else
|
else
|
||||||
if abs dx >= abs m1x2 + abs m2x1 &&
|
if abs dx > abs m1x2 + abs m2x1 &&
|
||||||
(if dy > 0
|
(if dy > 0
|
||||||
then abs dy >= abs m1y2 + abs m2y1
|
then abs dy > abs m1y2 + abs m2y1
|
||||||
else abs dy >= abs m1y1 + abs m2y2
|
else abs dy > abs m1y1 + abs m2y2
|
||||||
)
|
)
|
||||||
then 0
|
then 0
|
||||||
else -((abs m1x2 + abs m2x1) - abs dx + 1)
|
else -((abs m1x2 + abs m2x1) - abs dx)
|
||||||
by = if dy <= 0
|
by = if dy < 0
|
||||||
then
|
then
|
||||||
if abs dy >= abs m1y1 + abs m2y2 &&
|
if abs dy > abs m1y1 + abs m2y2 &&
|
||||||
(if dx > 0
|
(if dx > 0
|
||||||
then abs dx >= abs m1x2 + abs m2x1
|
then abs dx > abs m1x2 + abs m2x1
|
||||||
else abs dx >= abs m1x1 + abs m2x2
|
else abs dx > abs m1x1 + abs m2x2
|
||||||
)
|
)
|
||||||
then 0
|
then 0
|
||||||
else (abs m1y1 + abs m2y2) - abs dy + 1
|
else (abs m1y1 + abs m2y2) - abs dy
|
||||||
else
|
else
|
||||||
if abs dy >= abs m1y2 + abs m2y1 &&
|
if abs dy > abs m1y2 + abs m2y1 &&
|
||||||
(if dx > 0
|
(if dx > 0
|
||||||
then abs dx >= abs m1x2 + abs m2x1
|
then abs dx > abs m1x2 + abs m2x1
|
||||||
else abs dx >= abs m1x1 + abs m2x2
|
else abs dx > abs m1x1 + abs m2x2
|
||||||
)
|
)
|
||||||
then 0
|
then 0
|
||||||
else -((abs m1y2 + abs m2y1) - abs dy + 1)
|
else -((abs m1y2 + abs m2y1) - abs dy)
|
||||||
in
|
in
|
||||||
(velocityUpdater
|
(velocityUpdater
|
||||||
((positionUpdater mo1)
|
((positionUpdater mo1)
|
||||||
|
|
|
@ -59,6 +59,4 @@ class Mass m where
|
||||||
move dt m =
|
move dt m =
|
||||||
let dpos@(V2 dx dy) = (dt *) <$> velocity m
|
let dpos@(V2 dx dy) = (dt *) <$> velocity m
|
||||||
in
|
in
|
||||||
if dy < 0 && abs dy < 1
|
(positionUpdater m) (position m + dpos)
|
||||||
then (positionUpdater m) (position m + (V2 dx 0))
|
|
||||||
else (positionUpdater m) (position m + dpos)
|
|
||||||
|
|
|
@ -89,7 +89,6 @@ instance Actor Pituicat where
|
||||||
finalCat = physCat
|
finalCat = physCat
|
||||||
{ pcMoveVel =
|
{ pcMoveVel =
|
||||||
lerp (min 0.95 (59 * dt)) (pcMoveVel physCat) (pcTMoveVel physCat)
|
lerp (min 0.95 (59 * dt)) (pcMoveVel physCat) (pcTMoveVel physCat)
|
||||||
-- pcTMoveVel physCat
|
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
(A.log Debug (
|
(A.log Debug (
|
||||||
|
@ -152,14 +151,18 @@ instance Collidible Pituicat where
|
||||||
fromString (show other))
|
fromString (show other))
|
||||||
(
|
(
|
||||||
let ncat = (elasticCollision 0.3 cat other collr)
|
let ncat = (elasticCollision 0.3 cat other collr)
|
||||||
(V2 dx dy) = (ddt *) <$> (
|
nvel@(V2 dx dy) =
|
||||||
velocity ncat *
|
velocity ncat *
|
||||||
if dirx /= 0
|
if dirx == 0
|
||||||
then V2 0 1
|
then V2 0 1
|
||||||
else V2 1 1
|
else V2 1 1
|
||||||
)
|
grounded = (dy * ddt) <= 0 && (dy * ddt) > (-2) && diry == 0
|
||||||
in
|
in
|
||||||
ncat
|
ncat
|
||||||
{ pcGrounded = abs dy < 2
|
{ pcGrounded = grounded
|
||||||
|
, pcMoveVel = pcMoveVel ncat *
|
||||||
|
if dirx == 0
|
||||||
|
then V2 0 1
|
||||||
|
else V2 1 1
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue