Fix direction stuttering bug

This commit is contained in:
2021-09-22 19:42:39 +01:00
parent 0295b3dd70
commit 7b6904b51f
10 changed files with 59 additions and 93 deletions
+8 -5
View File
@@ -76,18 +76,21 @@ creatureTurnTo p cr
vToTarg = p -.- _crPos cr
dirToTarget = argV vToTarg
-- the following is perhaps not ideal because it mixes normalizeAngle with
-- angleVV, but it seems to work
creatureTurnTowardDir
:: Float -- ^ Angle
-> Float -- ^ Turn speed
-> Creature
-> Creature
creatureTurnTowardDir a turnSpeed cr
| vToTarg == V2 0 0 = cr -- this should deal with the angleVV error
| errorAngleVV 3 vToTarg (unitVectorAtAngle (_crDir cr)) <= turnSpeed
= cr & crDir .~ dirToTarget
| isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr) = cr & crDir +~ turnSpeed
| otherwise = cr & crDir -~ turnSpeed
| normalizeAngle (abs (a - cdir)) <= turnSpeed
= cr & crDir .~ dirToTarget
| isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr)
= cr & crDir +~ turnSpeed
| otherwise = cr & crDir -~ turnSpeed
where
cdir = _crDir cr
vToTarg = rotateV a (V2 1 0)
dirToTarget = argV vToTarg
+12 -21
View File
@@ -100,19 +100,17 @@ bpVector = V.fromList $ 0 : [0 .. 18]
movementSideEff :: Creature -> World -> World
movementSideEff cr w
| hasJetPack
= case cr ^? crStance . carriage of
Just (Boosting v)
-> makeFlameletTimed
(oldPos +.+ (_crRad cr + 3) *.* unitVectorAtAngle (_crDir cr + pi))
20
(momentum +.+ 1 *.* rotateV randDir (vInverse v))
Nothing
1
20
$ set randGen g
w
_ -> w
| hasJetPack = case cr ^? crStance . carriage of
Just (Boosting v)
-> makeFlameletTimed
(oldPos +.+ (_crRad cr + 3) *.* unitVectorAtAngle (_crDir cr + pi))
20
(momentum +.+ 1 *.* rotateV randDir (vInverse v))
Nothing
1
20
$ set randGen g w
_ -> w
| otherwise = footstepSideEffect cr w
where
hasJetPack = any (\it -> it ^? itIdentity == Just JetPack) $ _crInv cr
@@ -124,9 +122,6 @@ movementSideEff cr w
(randDir,g) = randomR (-0.5,0.5) $ _randGen w
(randAng,_) = randomR (0,2*pi) $ _randGen w
--crHasMoved = dist (_crPos cr) (_crOldPos cr) > 0.5
invSideEff :: Creature -> World -> World
invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr)
where
@@ -165,15 +160,11 @@ isFrictionless cr = case cr ^? crStance . carriage of
stepItemUseCooldown :: Creature -> Creature
stepItemUseCooldown cr = cr & crInv . ix iSel %~
(itUseTime %~ decreaseToZero) . (wpCurWarmUp %~ decreaseToZero)
--( over (crInv . ix iSel . itUseTime) decreaseToZero cr
where
iSel = _crInvSel cr
stepReloading :: Creature -> Creature
stepReloading cr
-- | crIsAiming' cr = cr
-- | otherwise
= over (crInv . ix iSel . wpReloadState) decreaseToZero cr
stepReloading cr = over (crInv . ix iSel . wpReloadState) decreaseToZero cr
where
iSel = _crInvSel cr
+1 -1
View File
@@ -38,7 +38,7 @@ wasdWithAiming
-> Creature
wasdWithAiming w speed i cr
| isAiming = set crDir mouseDir $ theMovement cr
| otherwise = theTurn $ theMovement cr
| otherwise = theMovement $ theTurn cr
where
theMovement
| movDir == V2 0 0 = id