Further tweak creature wall collisions

This commit is contained in:
2021-11-19 14:32:02 +00:00
parent 6f518d720c
commit 5658692ee4
6 changed files with 19 additions and 7 deletions
-1
View File
@@ -10,7 +10,6 @@ import Shape
import Geometry.Vector3D
import Geometry
import Linear.V3
defaultGun :: Item
defaultGun = Weapon
{ _itName = "default"
-1
View File
@@ -11,7 +11,6 @@ import Dodge.SoundLogic.LoadSound
import Dodge.WorldEvent
import Dodge.WorldEvent.Damage
import Dodge.Default
import Dodge.Item.Draw
import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Item.Weapon.TriggerType
import Dodge.Item.Weapon.AmmoParams
-1
View File
@@ -4,7 +4,6 @@ module Dodge.Item.Weapon.Bezier
import Dodge.Data
import Dodge.Base
import Dodge.Default.Weapon
import Dodge.Item.Draw
import Dodge.Item.Weapon.Targeting
import Dodge.Item.Weapon.BulletGuns
import Dodge.Item.Weapon.TriggerType
-1
View File
@@ -7,7 +7,6 @@ import Dodge.Default.Weapon
import Dodge.Default.Shell
import Dodge.SoundLogic.LoadSound
import Dodge.WorldEvent.Explosion
import Dodge.Item.Draw
import Dodge.Item.Weapon.Shell
import Dodge.Item.Weapon.Remote
import Dodge.Item.Weapon.TriggerType
-1
View File
@@ -13,7 +13,6 @@ import Dodge.SoundLogic.LoadSound
--import Dodge.Creature.Action
import Dodge.WorldEvent
import Dodge.Default
import Dodge.Item.Draw
--import Dodge.Item.Weapon.BulletGuns
--import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Item.Weapon.TriggerType
+19 -2
View File
@@ -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