From 82692124a4cb561c292e0bc34d5ccd8fee9bc7a4 Mon Sep 17 00:00:00 2001 From: charnet3d Date: Sat, 22 Apr 2023 08:26:18 +0000 Subject: [PATCH] Section 8: Advanced Movement - Lecture 124 Crouching Turn Animations --- Config/DefaultInput.ini | 2 + .../Belica/Meshes/Belica_Skeleton.uasset | 4 +- .../Animations/AimingAimOffset.uasset | 3 + .../Animations/Crouch_Idle_Rifle_Hip.uasset | 3 + .../Crouch_to_Stand_Rifle_Hip.uasset | 3 + .../Crouch_Turn_Left_90.uasset | 3 + .../Crouch_Turn_Right_90.uasset | 3 + .../MixamoCharacter/Ch21_1001_Diffuse.uasset | 3 + .../Ch21_1001_Glossiness.uasset | 3 + .../MixamoCharacter/Ch21_1001_Normal.uasset | 3 + .../MixamoCharacter/Ch21_1001_Specular.uasset | 3 + .../MixamoCharacter/Ch21_1002_Diffuse.uasset | 3 + .../MixamoCharacter/Ch21_1002_Normal.uasset | 3 + .../MixamoCharacter/Ch21_body.uasset | 3 + .../MixamoCharacter/Ch21_hair.uasset | 3 + .../Crouch_Turn_Right_90_skin.uasset | 3 + ...uch_Turn_Right_90_skin_PhysicsAsset.uasset | 3 + .../Crouch_Turn_Right_90_skin_Skeleton.uasset | 3 + .../Character/Animations/HipAimOffset.uasset | 3 + .../Animations/RunningBlendspace.uasset | 4 +- .../Stand_to_Crouch_Rifle_Hip.uasset | 3 + Content/_Game/Character/ShooterAnimBP.uasset | 4 +- Content/_Game/Maps/DefaultMap.umap | 2 +- Source/Shooter/ShooterAnimInstance.cpp | 88 ++++++++++++++----- Source/Shooter/ShooterAnimInstance.h | 50 ++++++++++- Source/Shooter/ShooterCharacter.cpp | 16 +++- Source/Shooter/ShooterCharacter.h | 13 ++- Source/Shooter/Weapon.cpp | 5 ++ Source/Shooter/Weapon.h | 2 + 29 files changed, 208 insertions(+), 36 deletions(-) create mode 100644 Content/_Game/Character/Animations/AimingAimOffset.uasset create mode 100644 Content/_Game/Character/Animations/Crouch_Idle_Rifle_Hip.uasset create mode 100644 Content/_Game/Character/Animations/Crouch_to_Stand_Rifle_Hip.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/AnimationsToRetarget/Crouch_Turn_Left_90.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/AnimationsToRetarget/Crouch_Turn_Right_90.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Diffuse.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Glossiness.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Normal.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Specular.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1002_Diffuse.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1002_Normal.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_body.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_hair.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin_PhysicsAsset.uasset create mode 100644 Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin_Skeleton.uasset create mode 100644 Content/_Game/Character/Animations/HipAimOffset.uasset create mode 100644 Content/_Game/Character/Animations/Stand_to_Crouch_Rifle_Hip.uasset diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index 45285b54..8c03c044 100644 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -88,6 +88,8 @@ DoubleClickTime=0.200000 +ActionMappings=(ActionName="Select",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Right) +ActionMappings=(ActionName="Reload",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=R) +ActionMappings=(ActionName="Reload",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Left) ++ActionMappings=(ActionName="Crouch",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=C) ++ActionMappings=(ActionName="Crouch",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_RightThumbstick) +AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=W) +AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=S) +AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=Gamepad_LeftY) diff --git a/Content/ParagonLtBelica/Characters/Heroes/Belica/Meshes/Belica_Skeleton.uasset b/Content/ParagonLtBelica/Characters/Heroes/Belica/Meshes/Belica_Skeleton.uasset index 454e5249..09a7d678 100644 --- a/Content/ParagonLtBelica/Characters/Heroes/Belica/Meshes/Belica_Skeleton.uasset +++ b/Content/ParagonLtBelica/Characters/Heroes/Belica/Meshes/Belica_Skeleton.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:69c95cf78870638e6015aa6b14fa91ab2bebbf5ec499f75e36e482339af5803c -size 57806 +oid sha256:a2b08f1aba2c0fa60f518f030904d3e2058f1ead43a9c707cc889df60bb33501 +size 57854 diff --git a/Content/_Game/Character/Animations/AimingAimOffset.uasset b/Content/_Game/Character/Animations/AimingAimOffset.uasset new file mode 100644 index 00000000..9451e5cb --- /dev/null +++ b/Content/_Game/Character/Animations/AimingAimOffset.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99da8c75e316d35491f1ffe49b26419395067d0e83df93fe1a5a258a204680fa +size 29796 diff --git a/Content/_Game/Character/Animations/Crouch_Idle_Rifle_Hip.uasset b/Content/_Game/Character/Animations/Crouch_Idle_Rifle_Hip.uasset new file mode 100644 index 00000000..43d128c6 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouch_Idle_Rifle_Hip.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4be0c957dfb6d369b797a75ed5304ebbfa010d00c094b05ec683d22ac374dcab +size 1029010 diff --git a/Content/_Game/Character/Animations/Crouch_to_Stand_Rifle_Hip.uasset b/Content/_Game/Character/Animations/Crouch_to_Stand_Rifle_Hip.uasset new file mode 100644 index 00000000..3b380bba --- /dev/null +++ b/Content/_Game/Character/Animations/Crouch_to_Stand_Rifle_Hip.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:76c451ce415f2791752dbdaafe9e1a0598faeea514ce3fa3d1a0fab036004a13 +size 195557 diff --git a/Content/_Game/Character/Animations/Crouching/AnimationsToRetarget/Crouch_Turn_Left_90.uasset b/Content/_Game/Character/Animations/Crouching/AnimationsToRetarget/Crouch_Turn_Left_90.uasset new file mode 100644 index 00000000..e5e2c7f4 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/AnimationsToRetarget/Crouch_Turn_Left_90.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f629e282cc6e201ea1929729a155cee42a218b740a54a2afb474d8c921370451 +size 244146 diff --git a/Content/_Game/Character/Animations/Crouching/AnimationsToRetarget/Crouch_Turn_Right_90.uasset b/Content/_Game/Character/Animations/Crouching/AnimationsToRetarget/Crouch_Turn_Right_90.uasset new file mode 100644 index 00000000..ffefc6b4 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/AnimationsToRetarget/Crouch_Turn_Right_90.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25207e9bf7a405c84f429ace2578276d7300f6cd362bc8a8d9b4e3302ada3348 +size 252908 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Diffuse.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Diffuse.uasset new file mode 100644 index 00000000..2b76e0b7 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Diffuse.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a2c868b3e34e4c7427397d68ba486f9e39c8820007ae1d82e045c4be61f9950 +size 16265486 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Glossiness.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Glossiness.uasset new file mode 100644 index 00000000..cdb3023b --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Glossiness.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6684f8c6ae82e00e6687d08ad3b8568905e19740c22aae93c71c5bc03f1df5ed +size 6121380 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Normal.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Normal.uasset new file mode 100644 index 00000000..2d9208b2 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Normal.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e90daff864eae4d79ad53d38dc6a70cfed875bfe105daceb77fd9f498229376 +size 22776160 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Specular.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Specular.uasset new file mode 100644 index 00000000..c19539bb --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1001_Specular.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6630c8899eac3fe9a74d534050932122d207d9308d70a607ff636536b675ebf +size 61841 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1002_Diffuse.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1002_Diffuse.uasset new file mode 100644 index 00000000..e06ebe31 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1002_Diffuse.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7343ea72d5da1e3e464c7e621bbf59d616e259cfbceb1d42fb8e1c46de68feaa +size 4412293 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1002_Normal.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1002_Normal.uasset new file mode 100644 index 00000000..97f05468 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_1002_Normal.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d781076dc1f75e1ce5dd699b5f5cffa03169216a6332ea918221300fba513cc4 +size 4684424 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_body.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_body.uasset new file mode 100644 index 00000000..b6884365 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_body.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc8f715c49eb4cef95cd01a931fee2506875c5f49dcca1551acdbb5938c1f605 +size 13267 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_hair.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_hair.uasset new file mode 100644 index 00000000..7b9f4b36 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Ch21_hair.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:922eb841f14862757d26035f6806cf1964c7100348dec8120e5dab108ce7546e +size 8829 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin.uasset new file mode 100644 index 00000000..6134ec6a --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:712f19d404c59a2f7fd492eb8bdb0e9eea2a2640824f5e88d6be2b1914b30102 +size 8505450 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin_PhysicsAsset.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin_PhysicsAsset.uasset new file mode 100644 index 00000000..2e6450ee --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin_PhysicsAsset.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31eefde9fe9c0c926441f3437ffddb884ce38545c4efa573761d4d93c0cf799e +size 29335 diff --git a/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin_Skeleton.uasset b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin_Skeleton.uasset new file mode 100644 index 00000000..8867b9b5 --- /dev/null +++ b/Content/_Game/Character/Animations/Crouching/MixamoCharacter/Crouch_Turn_Right_90_skin_Skeleton.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:76d7c6996db73bbfc6cc8a532dbfffcfe915933cd6219c64e8e18b6bc4982581 +size 28334 diff --git a/Content/_Game/Character/Animations/HipAimOffset.uasset b/Content/_Game/Character/Animations/HipAimOffset.uasset new file mode 100644 index 00000000..90338507 --- /dev/null +++ b/Content/_Game/Character/Animations/HipAimOffset.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a51707f2a2cffb52bd4f59e5fb248a2aa225e2fe4a6b8110de1865e735e8d78a +size 29772 diff --git a/Content/_Game/Character/Animations/RunningBlendspace.uasset b/Content/_Game/Character/Animations/RunningBlendspace.uasset index 1852b1b4..b3156397 100644 --- a/Content/_Game/Character/Animations/RunningBlendspace.uasset +++ b/Content/_Game/Character/Animations/RunningBlendspace.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a7613de202724b556d9e23c995d47008ba4fefede0586badd742d47ecc9af3b4 -size 8602 +oid sha256:0e9146f50cfd5f684364d4e20a510b79d876712298d0ef9eff721112cc7720d4 +size 28802 diff --git a/Content/_Game/Character/Animations/Stand_to_Crouch_Rifle_Hip.uasset b/Content/_Game/Character/Animations/Stand_to_Crouch_Rifle_Hip.uasset new file mode 100644 index 00000000..e672c035 --- /dev/null +++ b/Content/_Game/Character/Animations/Stand_to_Crouch_Rifle_Hip.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0014a91629a8dae8dd480ae924a0b0aa0078c7b029d7e25f8b924c419ae260b +size 224421 diff --git a/Content/_Game/Character/ShooterAnimBP.uasset b/Content/_Game/Character/ShooterAnimBP.uasset index d31836c7..f430cc32 100644 --- a/Content/_Game/Character/ShooterAnimBP.uasset +++ b/Content/_Game/Character/ShooterAnimBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d3c5916e2a64059c09330ada4ed3e32f6e97ffe72a423f50f0b3a96ec07e64da -size 778552 +oid sha256:6db3b9ccb6813eead219c17c9133cc848ec2c70ad0979fdc43fcfa7a8d8c440e +size 1059126 diff --git a/Content/_Game/Maps/DefaultMap.umap b/Content/_Game/Maps/DefaultMap.umap index 295b807f..2fdc05cd 100644 --- a/Content/_Game/Maps/DefaultMap.umap +++ b/Content/_Game/Maps/DefaultMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bb53fe39403373556c2bc992d2bd2207f52766a9805ae40cb6c4df1f7eafb2a3 +oid sha256:2bd51c10d546274a701dd20c0de324857b9bf0a0c508223f7ce6b80397758952 size 41735 diff --git a/Source/Shooter/ShooterAnimInstance.cpp b/Source/Shooter/ShooterAnimInstance.cpp index 51c48374..1328f3a9 100644 --- a/Source/Shooter/ShooterAnimInstance.cpp +++ b/Source/Shooter/ShooterAnimInstance.cpp @@ -14,9 +14,15 @@ UShooterAnimInstance::UShooterAnimInstance() : MovementOffsetYaw(0.f), LastMovementOffsetYaw(0.f), bAiming(false), - CharacterYaw(0.f), - CharacterYawLastFrame(0.f), - RootYawOffset(0.f) + TIPCharacterYaw(0.f), + TIPCharacterYawLastFrame(0.f), + RootYawOffset(0.f), + Pitch(0.f), + bReloading(false), + OffsetState(EOffsetState::EOS_Hip), + CharacterRotation(FRotator(0)), + CharacterRotationLastFrame(FRotator(0)), + YawDelta(0.f) { } @@ -26,8 +32,9 @@ void UShooterAnimInstance::UpdateAnimationProperties(float DeltaTime) ShooterCharacter = Cast(TryGetPawnOwner()); if (!ShooterCharacter) return; + - // Get the speed of the character from velocity + // Get the lateral speed of the character from velocity FVector Velocity{ ShooterCharacter->GetVelocity() }; Velocity.Z = 0; Speed = Velocity.Size(); @@ -49,8 +56,28 @@ void UShooterAnimInstance::UpdateAnimationProperties(float DeltaTime) } bAiming = ShooterCharacter->GetAiming(); - + bReloading = ShooterCharacter->GetCombatState() == ECombatState::ECS_Reloading; + bCrouching = ShooterCharacter->IsCrouching(); + + if (bReloading) + { + OffsetState = EOffsetState::EOS_Reloading; + } + else if (bIsInAir) + { + OffsetState = EOffsetState::EOS_InAir; + } + else if (bAiming) + { + OffsetState = EOffsetState::EOS_Aiming; + } + else + { + OffsetState = EOffsetState::EOS_Hip; + } + TurnInPlace(); + Lean(DeltaTime); } void UShooterAnimInstance::NativeInitializeAnimation() @@ -63,23 +90,26 @@ void UShooterAnimInstance::NativeInitializeAnimation() void UShooterAnimInstance::TurnInPlace() { if (!ShooterCharacter) return; - if (Speed > 0) + + Pitch = ShooterCharacter->GetBaseAimRotation().Pitch; + + if (Speed > 0 || bIsInAir) { // Don't want to turn in place; Character is moving RootYawOffset = 0.f; - CharacterYaw = ShooterCharacter->GetActorRotation().Yaw; - CharacterYawLastFrame = CharacterYaw; + TIPCharacterYaw = ShooterCharacter->GetActorRotation().Yaw; + TIPCharacterYawLastFrame = TIPCharacterYaw; RotationCurve = 0.f; RotationCurveLastFrame = 0.f; } else { - CharacterYawLastFrame = CharacterYaw; - CharacterYaw = ShooterCharacter->GetActorRotation().Yaw; - const float YawDelta { CharacterYaw - CharacterYawLastFrame }; - + TIPCharacterYawLastFrame = TIPCharacterYaw; + TIPCharacterYaw = ShooterCharacter->GetActorRotation().Yaw; + const float TIPYawDelta { TIPCharacterYaw - TIPCharacterYawLastFrame }; + // Root Yaw Offset, updated and clamped to [-180, 180] - RootYawOffset = UKismetMathLibrary::NormalizeAxis(RootYawOffset - YawDelta); + RootYawOffset = UKismetMathLibrary::NormalizeAxis(RootYawOffset - TIPYawDelta); // 1.0 if turning, 0.0 if not const float Turning { GetCurveValue(TEXT("Turning")) }; @@ -99,14 +129,28 @@ void UShooterAnimInstance::TurnInPlace() RootYawOffset > 0 ? RootYawOffset -= YawExcess : RootYawOffset += YawExcess; } } - - /*if (GEngine) - { - GEngine->AddOnScreenDebugMessage(1, -1, FColor::Blue, - FString::Printf(TEXT("CharacterYaw: %f"), CharacterYaw)); - - GEngine->AddOnScreenDebugMessage(2, -1, FColor::Red, - FString::Printf(TEXT("RootYawOffset: %f"), RootYawOffset)); - }*/ } } + +void UShooterAnimInstance::Lean(float DeltaTime) +{ + if (!ShooterCharacter) return; + + CharacterRotationLastFrame = CharacterRotation; + CharacterRotation = ShooterCharacter->GetActorRotation(); + + const FRotator Delta { UKismetMathLibrary::NormalizedDeltaRotator(CharacterRotation, CharacterRotationLastFrame) }; + const double Target { Delta.Yaw / DeltaTime }; + const double Interp { FMath::FInterpTo(YawDelta, Target, DeltaTime, 6.f) }; + YawDelta = FMath::Clamp(Interp, -90.f, 90.f); + + // if (GEngine) + // { + // GEngine->AddOnScreenDebugMessage( + // 3, + // -1, + // FColor::Cyan, + // FString::Printf(TEXT("YawDelta: %f"), YawDelta) + // ); + // } +} diff --git a/Source/Shooter/ShooterAnimInstance.h b/Source/Shooter/ShooterAnimInstance.h index 89e4beac..5d9bee89 100644 --- a/Source/Shooter/ShooterAnimInstance.h +++ b/Source/Shooter/ShooterAnimInstance.h @@ -7,6 +7,19 @@ #include "ShooterAnimInstance.generated.h" class AShooterCharacter; + + +UENUM(BlueprintType) +enum class EOffsetState : uint8 +{ + EOS_Aiming UMETA(DisplayName = "Aiming"), + EOS_Hip UMETA(DisplayName = "Hip"), + EOS_Reloading UMETA(DisplayName = "Reloading"), + EOS_InAir UMETA(DisplayName = "InAir"), + + EOS_MAX UMETA(DisplayName = "DefaultMax") +}; + /** * */ @@ -27,6 +40,9 @@ public: protected: /** Handle turning in place variables */ void TurnInPlace(); + + /** Handle calculations for leaning while running */ + void Lean(float DeltaTime); private: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = true)) @@ -55,11 +71,11 @@ private: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = true)) bool bAiming; - /** Yaw of the character this frame */ - float CharacterYaw; + /** Turn In Place: Yaw of the character this frame; Only updated when standing still and not in the air */ + float TIPCharacterYaw; - /** Yaw of the character the previous frame */ - float CharacterYawLastFrame; + /** Turn In Place: Yaw of the character the previous frame; Only updated when standing still and not in the air */ + float TIPCharacterYawLastFrame; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Turn In Place", meta = (AllowPrivateAccess = true)) float RootYawOffset; @@ -69,4 +85,30 @@ private: /** Rotation curve value last frame */ float RotationCurveLastFrame; + + /** The pitch of the aim rotation used for aim offset */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Turn In Place", meta = (AllowPrivateAccess = true)) + float Pitch; + + /** True when reloading, used to prevent aim offset when reloading */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Turn In Place", meta = (AllowPrivateAccess = true)) + bool bReloading; + + /** Offset state; used to determine which Aim Offset to use */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Turn In Place", meta = (AllowPrivateAccess = true)) + EOffsetState OffsetState; + + /** Yaw of the character this frame */ + FRotator CharacterRotation; + + /** Yaw of the character the previous frame */ + FRotator CharacterRotationLastFrame; + + /** Yaw delta used for leaning while running in the blendspace */ + UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Lean", meta = (AllowPrivateAccess = true)) + double YawDelta; + + /** True when crouching */ + UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Crouching", meta = (AllowPrivateAccess = true)) + bool bCrouching; }; diff --git a/Source/Shooter/ShooterCharacter.cpp b/Source/Shooter/ShooterCharacter.cpp index dfebc9c0..b318969a 100644 --- a/Source/Shooter/ShooterCharacter.cpp +++ b/Source/Shooter/ShooterCharacter.cpp @@ -60,7 +60,8 @@ AShooterCharacter::AShooterCharacter() : Starting9mmAmmo(85), StartingARAmmo(120), // Combat variables - CombatState(ECombatState::ECS_Unoccupied) + CombatState(ECombatState::ECS_Unoccupied), + bCrouching(false) { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; @@ -149,6 +150,9 @@ void AShooterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCo PlayerInputComponent->BindAction("Reload", IE_Pressed, this, &AShooterCharacter::ReloadButtonPressed); + + PlayerInputComponent->BindAction("Crouch", IE_Pressed, this, + &AShooterCharacter::CrouchButtonPressed); } // Called every frame @@ -686,7 +690,7 @@ void AShooterCharacter::ReloadWeapon() if (!EquippedWeapon) return; // Do we have ammo for the correct type - if (CarryingAmmo() && EquippedWeapon->GetAmmo() < EquippedWeapon->GetMagazineCapacity()) + if (CarryingAmmo() && !EquippedWeapon->ClipIsFull()) { CombatState = ECombatState::ECS_Reloading; UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); @@ -759,3 +763,11 @@ void AShooterCharacter::ReleaseClip() { EquippedWeapon->SetMovingClip(false); } + +void AShooterCharacter::CrouchButtonPressed() +{ + if (!GetCharacterMovement()->IsFalling()) + { + bCrouching = !bCrouching; + } +} diff --git a/Source/Shooter/ShooterCharacter.h b/Source/Shooter/ShooterCharacter.h index 35f7549f..614c9d99 100644 --- a/Source/Shooter/ShooterCharacter.h +++ b/Source/Shooter/ShooterCharacter.h @@ -161,6 +161,9 @@ protected: /** Called from Animation Blueprint with ReleaseClip notify */ UFUNCTION(BlueprintCallable) void ReleaseClip(); + + void CrouchButtonPressed(); + private: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true)) USpringArmComponent* CameraBoom; @@ -337,7 +340,11 @@ private: /* Scene component to attach to the Character's hand when reloading */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat, meta = (AllowPrivateAccess = true)) USceneComponent* HandSceneComponent; - + + /** True when crouching */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = true)) + bool bCrouching; + public: /* Returns CameraBoom SubObject */ FORCEINLINE USpringArmComponent* GetCameraBoom() const { return CameraBoom; } @@ -358,4 +365,8 @@ public: FVector GetCameraInterpLocation(); void GetPickupItem(AItem* Item); + + FORCEINLINE ECombatState GetCombatState() const { return CombatState; } + + FORCEINLINE bool IsCrouching() const { return bCrouching; } }; diff --git a/Source/Shooter/Weapon.cpp b/Source/Shooter/Weapon.cpp index 181d4d3e..ba39ed85 100644 --- a/Source/Shooter/Weapon.cpp +++ b/Source/Shooter/Weapon.cpp @@ -65,6 +65,11 @@ void AWeapon::ReloadAmmo(int32 Amount) Ammo += Amount; } +bool AWeapon::ClipIsFull() +{ + return Ammo >= MagazineCapacity; +} + void AWeapon::StopFalling() { bFalling = false; diff --git a/Source/Shooter/Weapon.h b/Source/Shooter/Weapon.h index 6e410fc0..371b68f2 100644 --- a/Source/Shooter/Weapon.h +++ b/Source/Shooter/Weapon.h @@ -86,4 +86,6 @@ public: void ReloadAmmo(int32 Amount); FORCEINLINE void SetMovingClip(bool Move) { bMovingClip = Move; }; + + bool ClipIsFull(); };