interaction in y direction works

This commit is contained in:
nek0 2021-07-25 16:14:05 +02:00
parent 0a2e3f05d4
commit 337fcf9cd0

View file

@ -182,14 +182,14 @@ class (Show c, Mass c) => Collidible c where
NoCollision ->
if overlap
then
let xoverlap = floor (minimum
let xoverlap = floor (maximum (filter (0 >)
[ pm2b2x - pm2b1x
, pm2b1x - pm1b2x
])
yoverlap = floor (minimum
]))
yoverlap = floor (maximum (filter (0 >)
[ pm2b1y - pm1b2y
, pm2b2y - pm1b1y
])
]))
in
if xoverlap < yoverlap
then
@ -201,7 +201,7 @@ class (Show c, Mass c) => Collidible c where
else
if yoverlap < 0
then OverlapCollision
(V2 yoverlap 0)
(V2 0 yoverlap)
else NoCollision
else NoCollision
_ -> A.log
@ -259,6 +259,13 @@ elasticCollision damping mo1 (mo2, OverlapCollision depth) dt =
v1y' = 2 * (m1 * dy + m2 * (-dy)) / (m1 + m2) - dy
nvel = if m1 == recip 0
then V2 0 0
else (damping *) <$> V2 v1x' v1y'
else (damping *) <$>
if m2 == recip 0
then
if dx /= 0
then V2 (-v1x') v1y'
else V2 v1x' (-v1y')
else
V2 v1x' v1y'
in
velocityUpdater mo1 nvel