Further tweak creature wall collisions
This commit is contained in:
@@ -26,8 +26,8 @@ colCrWall w c
|
||||
| _crPos c' == _crPos c'' = c'
|
||||
| otherwise = c & crPos .~ _crOldPos c
|
||||
where
|
||||
c'' = c & crPos %~ pushOutFromWalls rad ls
|
||||
c' = c & crPos %~ pushOutFromWalls rad (reverse ls)
|
||||
c'' = c' & crPos %~ pushOutFromWalls rad ls
|
||||
c' = c & crPos %~ pushOutFromWalls' rad (reverse ls)
|
||||
. pushOutFromWalls rad ls
|
||||
. flip (collidePointWalls p1) wls -- check push throughs
|
||||
rad = _crRad c + wallBuffer
|
||||
@@ -51,6 +51,12 @@ pushOutFromWalls rad wls p1 = case (getFirst . foldMap (First . pushOutFromWall
|
||||
Just p2 -> fromMaybe p2 $ (getLast . foldMap (Last . pushOutFromWall rad p2)) wls
|
||||
-- possible improvement: choose between the closer of p2 and "p3" to p1
|
||||
|
||||
pushOutFromWalls' :: Float -> [(Point2,Point2)] -> Point2 -> Point2
|
||||
pushOutFromWalls' rad wls p1 = case (getFirst . foldMap (First . pushOutFromWall' rad p1)) wls of
|
||||
Nothing -> p1
|
||||
Just p2 -> fromMaybe p2 $ (getLast . foldMap (Last . pushOutFromWall' rad p2)) wls
|
||||
-- possible improvement: choose between the closer of p2 and "p3" to p1
|
||||
|
||||
pushOrCrush :: [(Point2,Point2)] -> Creature -> Creature
|
||||
pushOrCrush wls cr = case mapMaybe (pushOutFromWall (_crRad cr) cpos) wls of
|
||||
[] -> cr
|
||||
@@ -73,6 +79,17 @@ pushOutFromWall rad cp2 (wp1,wp2)
|
||||
wp2' = wp2 +.+ rad *.* norm
|
||||
newP = errorClosestPointOnLine 5 wp1' wp2' cp2
|
||||
isOnWall = circOnSegNoEndpoints wp1 wp2 cp2 rad
|
||||
pushOutFromWall' :: Float -> Point2 -> (Point2,Point2) -> Maybe Point2
|
||||
pushOutFromWall' rad cp2 (wp1,wp2)
|
||||
| isOnWall = Just newP
|
||||
| otherwise = Nothing
|
||||
where
|
||||
norm = errorNormalizeV 61 $ vNormal (wp1 -.- wp2)
|
||||
wp1' = wp1 +.+ rad *.* norm
|
||||
wp2' = wp2 +.+ rad *.* norm
|
||||
newP = errorClosestPointOnLine 5 wp1' wp2' cp2
|
||||
--isOnWall = circOnSegNoEndpoints wp1 wp2 cp2 rad
|
||||
isOnWall = circOnSeg wp1 wp2 cp2 rad
|
||||
|
||||
--pushOutFromCorners :: World -> Creature -> Creature
|
||||
--pushOutFromCorners w cr = cr & crPos .~ newPos
|
||||
|
||||
Reference in New Issue
Block a user