diff --git a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset index 286021b..1f9eaee 100644 Binary files a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset and b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset differ diff --git a/Content/Blueprints/Character/Animation/EquippedRun.uasset b/Content/Blueprints/Character/Animation/EquippedRun.uasset index 0f6fced..36bf98d 100644 Binary files a/Content/Blueprints/Character/Animation/EquippedRun.uasset and b/Content/Blueprints/Character/Animation/EquippedRun.uasset differ diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index f85c373..d4b2d5c 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Source/Blaster/Character/BlasterAnimInstance.cpp b/Source/Blaster/Character/BlasterAnimInstance.cpp index 20866f9..9a5b6b5 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.cpp +++ b/Source/Blaster/Character/BlasterAnimInstance.cpp @@ -5,6 +5,7 @@ #include "BlasterCharacter.h" #include "GameFramework/CharacterMovementComponent.h" +#include "Kismet/KismetMathLibrary.h" void UBlasterAnimInstance::NativeInitializeAnimation() { @@ -33,4 +34,18 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) bWeaponEquipped = BlasterCharacter->IsWeaponEquipped(); bIsCrouched = BlasterCharacter->bIsCrouched; bAiming = BlasterCharacter->IsAiming(); + + // Offset Yaw for Strafing + FRotator AimRotation = BlasterCharacter->GetBaseAimRotation(); + FRotator MovementRotation = UKismetMathLibrary::MakeRotFromX(BlasterCharacter->GetVelocity()); + FRotator DeltaRot = UKismetMathLibrary::NormalizedDeltaRotator(MovementRotation, AimRotation); + DeltaRotation = FMath::RInterpTo(DeltaRotation, DeltaRot, DeltaSeconds, 6.f); + YawOffset = DeltaRotation.Yaw; + + CharacterRotationLastFrame = CharacterRotation; + CharacterRotation = BlasterCharacter->GetActorRotation(); + const FRotator Delta = UKismetMathLibrary::NormalizedDeltaRotator(CharacterRotation, CharacterRotationLastFrame); + const float Target = Delta.Yaw / DeltaSeconds; + const float Interp = FMath::FInterpTo(Lean, Target, DeltaSeconds, 6.f); + Lean = FMath::Clamp(Interp, -90.f, 90.f); } diff --git a/Source/Blaster/Character/BlasterAnimInstance.h b/Source/Blaster/Character/BlasterAnimInstance.h index 37b3c11..635ac2e 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.h +++ b/Source/Blaster/Character/BlasterAnimInstance.h @@ -41,4 +41,14 @@ private: UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) bool bAiming; + + UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) + float YawOffset; + + UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) + float Lean; + + FRotator CharacterRotationLastFrame; + FRotator CharacterRotation; + FRotator DeltaRotation; }; diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 19f3cf6..1913422 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -6,6 +6,7 @@ #include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Weapon/Weapon.h" #include "Engine/SkeletalMeshSocket.h" +#include "GameFramework/CharacterMovementComponent.h" #include "Net/UnrealNetwork.h" UCombatComponent::UCombatComponent() @@ -24,6 +25,15 @@ void UCombatComponent::SetAiming(bool bIsAiming) ServerSetAiming(bIsAiming); } +void UCombatComponent::OnRep_EquippedWeapon() +{ + if (EquippedWeapon && Character) + { + Character->GetCharacterMovement()->bOrientRotationToMovement = false; + Character->bUseControllerRotationYaw = true; + } +} + void UCombatComponent::ServerSetAiming_Implementation(bool bIsAiming) { bAiming = bIsAiming; @@ -55,4 +65,6 @@ void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip) HandSocket->AttachActor(EquippedWeapon, Character->GetMesh()); } EquippedWeapon->SetOwner(Character); + Character->GetCharacterMovement()->bOrientRotationToMovement = false; + Character->bUseControllerRotationYaw = true; } diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index 23f52e9..54df2c8 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -28,10 +28,13 @@ protected: UFUNCTION(Server, Reliable) void ServerSetAiming(bool bIsAiming); + UFUNCTION() + void OnRep_EquippedWeapon(); + private: class ABlasterCharacter* Character; - UPROPERTY(Replicated) + UPROPERTY(ReplicatedUsing=OnRep_EquippedWeapon) class AWeapon* EquippedWeapon; UPROPERTY(Replicated)