diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 4e19e048..f1138c37 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -1,8 +1,8 @@ [/Script/EngineSettings.GameMapsSettings] -GameDefaultMap=/Game/ModSciInteriors/Maps/Example_2_Dynamic.Example_2_Dynamic -EditorStartupMap=/Game/ModSciInteriors/Maps/Example_2_Dynamic.Example_2_Dynamic +GameDefaultMap=/Game/_Game/Maps/DefaultMap.DefaultMap +EditorStartupMap=/Game/_Game/Maps/DefaultMap.DefaultMap GlobalDefaultGameMode=/Game/_Game/GameMode/ShooterGameModeBaseBP.ShooterGameModeBaseBP_C [/Script/HardwareTargeting.HardwareTargetingSettings] diff --git a/Content/ParagonLtBelica/Characters/Heroes/Belica/Meshes/Belica_Skeleton.uasset b/Content/ParagonLtBelica/Characters/Heroes/Belica/Meshes/Belica_Skeleton.uasset index c554da42..454e5249 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:9ff7e5c8cafe9b62f74d478f18d6b66dd4048ebbf0a4984c0b974c77feb7b738 -size 57756 +oid sha256:69c95cf78870638e6015aa6b14fa91ab2bebbf5ec499f75e36e482339af5803c +size 57806 diff --git a/Content/_Game/Character/Animations/Idle_Turn_90_Left_Trimmed.uasset b/Content/_Game/Character/Animations/Idle_Turn_90_Left_Trimmed.uasset new file mode 100644 index 00000000..d1084874 --- /dev/null +++ b/Content/_Game/Character/Animations/Idle_Turn_90_Left_Trimmed.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46be27bb1c100743c8dbb67c7c9503bca21d89633d5122d8e10f6739375a2320 +size 136162 diff --git a/Content/_Game/Character/Animations/Idle_Turn_90_Right_Trimmed.uasset b/Content/_Game/Character/Animations/Idle_Turn_90_Right_Trimmed.uasset new file mode 100644 index 00000000..cfc83b56 --- /dev/null +++ b/Content/_Game/Character/Animations/Idle_Turn_90_Right_Trimmed.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a84fbb31214ec654ef8cdb564a1843de195cb6364bd25ccfa925d6192c3f316b +size 161443 diff --git a/Content/_Game/Character/Animations/Jog_Bwd_Stop_Trimmed2.uasset b/Content/_Game/Character/Animations/Jog_Bwd_Stop_Trimmed2.uasset deleted file mode 100644 index 8816f872..00000000 --- a/Content/_Game/Character/Animations/Jog_Bwd_Stop_Trimmed2.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ea499b26b1ff7085faf02c40cb4642ecb7c60c09db55a5f7de4d85aea8e4be60 -size 1199 diff --git a/Content/_Game/Character/Animations/Jog_Left_Start_Trimmed2.uasset b/Content/_Game/Character/Animations/Jog_Left_Start_Trimmed2.uasset deleted file mode 100644 index 666b6c91..00000000 --- a/Content/_Game/Character/Animations/Jog_Left_Start_Trimmed2.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:7b8c1a9f82a3ae31625ce118399a72146e4249f1c1b9c8dbdfffc91861ff6682 -size 1215 diff --git a/Content/_Game/Character/Animations/Jog_Right_Start_Trimmed2.uasset b/Content/_Game/Character/Animations/Jog_Right_Start_Trimmed2.uasset deleted file mode 100644 index 91d9c5b2..00000000 --- a/Content/_Game/Character/Animations/Jog_Right_Start_Trimmed2.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:47ee89e3a2a3584ffc0f9b4b2915c59f0a653ce08699975527a7dddfc6cd1dde -size 1223 diff --git a/Content/_Game/Character/ShooterAnimBP.uasset b/Content/_Game/Character/ShooterAnimBP.uasset index 4e9add60..d31836c7 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:1e80b217fc1751c55b0543b8d5f762ef69b0484662e8d6446c3dc67e0c40a413 -size 578436 +oid sha256:d3c5916e2a64059c09330ada4ed3e32f6e97ffe72a423f50f0b3a96ec07e64da +size 778552 diff --git a/Content/_Game/Maps/DefaultMap.umap b/Content/_Game/Maps/DefaultMap.umap index 51979a4b..295b807f 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:89cd539bab5e548952c5c9651adfe2723c4e5ef2b9d611052d463150026704a4 -size 35019 +oid sha256:bb53fe39403373556c2bc992d2bd2207f52766a9805ae40cb6c4df1f7eafb2a3 +size 41735 diff --git a/Source/Shooter/ShooterAnimInstance.cpp b/Source/Shooter/ShooterAnimInstance.cpp index 926c7028..51c48374 100644 --- a/Source/Shooter/ShooterAnimInstance.cpp +++ b/Source/Shooter/ShooterAnimInstance.cpp @@ -7,36 +7,50 @@ #include "GameFramework/CharacterMovementComponent.h" #include "Kismet/KismetMathLibrary.h" +UShooterAnimInstance::UShooterAnimInstance() : + Speed(0.f), + bIsInAir(false), + bIsAccelerating(false), + MovementOffsetYaw(0.f), + LastMovementOffsetYaw(0.f), + bAiming(false), + CharacterYaw(0.f), + CharacterYawLastFrame(0.f), + RootYawOffset(0.f) +{ +} + void UShooterAnimInstance::UpdateAnimationProperties(float DeltaTime) { - if (ShooterCharacter) + if (!ShooterCharacter) ShooterCharacter = Cast(TryGetPawnOwner()); - if (ShooterCharacter) + if (!ShooterCharacter) return; + + // Get the speed of the character from velocity + FVector Velocity{ ShooterCharacter->GetVelocity() }; + Velocity.Z = 0; + Speed = Velocity.Size(); + + // Is the character in the air + bIsInAir = ShooterCharacter->GetCharacterMovement()->IsFalling(); + + // Is the character accelerating + bIsAccelerating = ShooterCharacter->GetCharacterMovement()->GetCurrentAcceleration().Size() > 0; + + FRotator AimRotation = ShooterCharacter->GetBaseAimRotation(); + FRotator MovementRotation = UKismetMathLibrary::MakeRotFromX(ShooterCharacter->GetVelocity()); + + MovementOffsetYaw = UKismetMathLibrary::NormalizedDeltaRotator(MovementRotation, AimRotation).Yaw; + + if (ShooterCharacter->GetVelocity().Size() > 0) { - // Get the speed of the character from velocity - FVector Velocity{ ShooterCharacter->GetVelocity() }; - Velocity.Z = 0; - Speed = Velocity.Size(); - - // Is the character in the air - bIsInAir = ShooterCharacter->GetCharacterMovement()->IsFalling(); - - // Is the character accelerating - bIsAccelerating = ShooterCharacter->GetCharacterMovement()->GetCurrentAcceleration().Size() > 0; - - FRotator AimRotation = ShooterCharacter->GetBaseAimRotation(); - FRotator MovementRotation = UKismetMathLibrary::MakeRotFromX(ShooterCharacter->GetVelocity()); - - MovementOffsetYaw = UKismetMathLibrary::NormalizedDeltaRotator(MovementRotation, AimRotation).Yaw; - - if (ShooterCharacter->GetVelocity().Size() > 0) - { - LastMovementOffsetYaw = MovementOffsetYaw; - } - - bAiming = ShooterCharacter->GetAiming(); + LastMovementOffsetYaw = MovementOffsetYaw; } + + bAiming = ShooterCharacter->GetAiming(); + + TurnInPlace(); } void UShooterAnimInstance::NativeInitializeAnimation() @@ -45,3 +59,54 @@ void UShooterAnimInstance::NativeInitializeAnimation() ShooterCharacter = Cast(TryGetPawnOwner()); } + +void UShooterAnimInstance::TurnInPlace() +{ + if (!ShooterCharacter) return; + if (Speed > 0) + { + // Don't want to turn in place; Character is moving + RootYawOffset = 0.f; + CharacterYaw = ShooterCharacter->GetActorRotation().Yaw; + CharacterYawLastFrame = CharacterYaw; + RotationCurve = 0.f; + RotationCurveLastFrame = 0.f; + } + else + { + CharacterYawLastFrame = CharacterYaw; + CharacterYaw = ShooterCharacter->GetActorRotation().Yaw; + const float YawDelta { CharacterYaw - CharacterYawLastFrame }; + + // Root Yaw Offset, updated and clamped to [-180, 180] + RootYawOffset = UKismetMathLibrary::NormalizeAxis(RootYawOffset - YawDelta); + + // 1.0 if turning, 0.0 if not + const float Turning { GetCurveValue(TEXT("Turning")) }; + if (Turning) + { + RotationCurveLastFrame = RotationCurve; + RotationCurve = GetCurveValue(TEXT("Rotation")); + const float DeltaRotation { RotationCurve = RotationCurveLastFrame }; + + // If RootYawOffset > 0, -> Turning Left, If RootYawOffset < 0, -> Turning Right + RootYawOffset > 0 ? RootYawOffset -= DeltaRotation : RootYawOffset += DeltaRotation; + + const float ABSRootYawOffset { FMath::Abs(RootYawOffset) }; + if (ABSRootYawOffset) + { + const float YawExcess { ABSRootYawOffset - 90.f }; + 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)); + }*/ + } +} diff --git a/Source/Shooter/ShooterAnimInstance.h b/Source/Shooter/ShooterAnimInstance.h index ca5587d1..89e4beac 100644 --- a/Source/Shooter/ShooterAnimInstance.h +++ b/Source/Shooter/ShooterAnimInstance.h @@ -17,11 +17,16 @@ class SHOOTER_API UShooterAnimInstance : public UAnimInstance public: + UShooterAnimInstance(); + UFUNCTION(BlueprintCallable) void UpdateAnimationProperties(float DeltaTime); virtual void NativeInitializeAnimation() override; +protected: + /** Handle turning in place variables */ + void TurnInPlace(); private: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = true)) @@ -49,4 +54,19 @@ private: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = true)) bool bAiming; + + /** Yaw of the character this frame */ + float CharacterYaw; + + /** Yaw of the character the previous frame */ + float CharacterYawLastFrame; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Turn In Place", meta = (AllowPrivateAccess = true)) + float RootYawOffset; + + /** Rotation curve value this frame */ + float RotationCurve; + + /** Rotation curve value last frame */ + float RotationCurveLastFrame; };