51 - Leaning and Strafing
This commit is contained in:
parent
2125d3ee9f
commit
0729f5145e
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue