diff --git a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset index 801f739..756099b 100644 Binary files a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset and b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset differ diff --git a/Source/Blaster/Character/BlasterAnimInstance.cpp b/Source/Blaster/Character/BlasterAnimInstance.cpp index 9a5b6b5..ab1397e 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.cpp +++ b/Source/Blaster/Character/BlasterAnimInstance.cpp @@ -48,4 +48,7 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) const float Target = Delta.Yaw / DeltaSeconds; const float Interp = FMath::FInterpTo(Lean, Target, DeltaSeconds, 6.f); Lean = FMath::Clamp(Interp, -90.f, 90.f); + + AO_Yaw = BlasterCharacter->GetAO_Yaw(); + AO_Pitch = BlasterCharacter->GetAO_Pitch(); } diff --git a/Source/Blaster/Character/BlasterAnimInstance.h b/Source/Blaster/Character/BlasterAnimInstance.h index 635ac2e..65ebf40 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.h +++ b/Source/Blaster/Character/BlasterAnimInstance.h @@ -47,6 +47,12 @@ private: UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) float Lean; + + UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) + float AO_Yaw; + + UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) + float AO_Pitch; FRotator CharacterRotationLastFrame; FRotator CharacterRotation; diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index d3a7636..08f0e9f 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -10,6 +10,7 @@ #include "Components/WidgetComponent.h" #include "GameFramework/CharacterMovementComponent.h" #include "GameFramework/SpringArmComponent.h" +#include "Kismet/KismetMathLibrary.h" #include "Net/UnrealNetwork.h" @@ -65,6 +66,8 @@ void ABlasterCharacter::BeginPlay() void ABlasterCharacter::Tick(float DeltaTime) { Super::Tick(DeltaTime); + + AimOffset(DeltaTime); } void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) @@ -158,6 +161,32 @@ void ABlasterCharacter::AimButtonReleased() } } +void ABlasterCharacter::AimOffset(float DeltaTime) +{ + if (Combat && Combat->EquippedWeapon == nullptr) return; + + FVector Velocity = GetVelocity(); + Velocity.Z = 0.f; + float Speed = Velocity.Size(); + bool bIsInAir = GetCharacterMovement()->IsFalling(); + + if (Speed == 0.f && !bIsInAir) // Standing still, not jumping + { + FRotator CurrentAimRotation = FRotator(0.f, GetBaseAimRotation().Yaw, 0.f); + FRotator DeltaAimRotation = UKismetMathLibrary::NormalizedDeltaRotator(CurrentAimRotation, StartingAimRotation); + AO_Yaw = DeltaAimRotation.Yaw; + bUseControllerRotationYaw = false; + } + if (Speed > 0.f || bIsInAir) // Running or jumping + { + StartingAimRotation = FRotator(0.f, GetBaseAimRotation().Yaw, 0.f); + AO_Yaw = 0.f; + bUseControllerRotationYaw = true; + } + + AO_Pitch = GetBaseAimRotation().Pitch; +} + void ABlasterCharacter::ServerEquipButtonPressed_Implementation() { EquipButtonPressed(); diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index bd2c233..925f599 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -29,6 +29,7 @@ protected: void CrouchButtonPressed(); void AimButtonPressed(); void AimButtonReleased(); + void AimOffset(float DeltaTime); private: UPROPERTY(VisibleAnywhere, Category="Camera") @@ -51,8 +52,14 @@ private: UFUNCTION(Server, Reliable) void ServerEquipButtonPressed(); + + float AO_Yaw; + float AO_Pitch; + FRotator StartingAimRotation; public: void SetOverlappingWeapon(AWeapon* Weapon); bool IsWeaponEquipped(); bool IsAiming(); + FORCEINLINE float GetAO_Yaw() const { return AO_Yaw; }; + FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; }; };