201 - Swap Weapon Animation
This commit is contained in:
parent
9e64e70607
commit
d6ce6fc25f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -74,7 +74,11 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaTime)
|
|||
}
|
||||
|
||||
bUseFABRIK = BlasterCharacter->GetCombatState() == ECombatState::ECS_Unoccupied;
|
||||
if (BlasterCharacter->IsLocallyControlled() && BlasterCharacter->GetCombatState() != ECombatState::ECS_ThrowingGrenade)
|
||||
bool bFABRIKOverride = BlasterCharacter->IsLocallyControlled() &&
|
||||
BlasterCharacter->GetCombatState() != ECombatState::ECS_ThrowingGrenade &&
|
||||
BlasterCharacter->bFinishedSwapping;
|
||||
|
||||
if (bFABRIKOverride)
|
||||
{
|
||||
bUseFABRIK = !BlasterCharacter->IsLocallyReloading();
|
||||
}
|
||||
|
|
|
@ -434,6 +434,15 @@ void ABlasterCharacter::PlayThrowGrenadeMontage()
|
|||
}
|
||||
}
|
||||
|
||||
void ABlasterCharacter::PlaySwapMontage()
|
||||
{
|
||||
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
|
||||
if (AnimInstance && SwapMontage)
|
||||
{
|
||||
AnimInstance->Montage_Play(SwapMontage);
|
||||
}
|
||||
}
|
||||
|
||||
void ABlasterCharacter::PlayHitReactMontage()
|
||||
{
|
||||
if (Combat == nullptr || Combat->PrimaryWeapon == nullptr) return;
|
||||
|
@ -524,7 +533,18 @@ void ABlasterCharacter::EquipButtonPressed()
|
|||
if (bDisableGameplay) return;
|
||||
if (Combat)
|
||||
{
|
||||
ServerEquipButtonPressed();
|
||||
if (Combat->CombatState == ECombatState::ECS_Unoccupied) ServerEquipButtonPressed();
|
||||
bool bSwap = Combat->ShouldSwapWeapons() &&
|
||||
!HasAuthority() &&
|
||||
Combat->CombatState == ECombatState::ECS_Unoccupied &&
|
||||
OverlappingWeapon == nullptr;
|
||||
|
||||
if (bSwap)
|
||||
{
|
||||
PlaySwapMontage();
|
||||
Combat->CombatState = ECombatState::ECS_SwappingWeapons;
|
||||
bFinishedSwapping = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,13 @@ public:
|
|||
virtual void OnRep_ReplicatedMovement() override;
|
||||
virtual void Destroyed() override;
|
||||
void RotateInPlace(float DeltaTime);
|
||||
|
||||
// Play Montages
|
||||
void PlayFireMontage(bool bAiming);
|
||||
void PlayReloadMontage();
|
||||
void PlayEliminatedMontage();
|
||||
void PlayThrowGrenadeMontage();
|
||||
void PlaySwapMontage();
|
||||
|
||||
void Eliminated();
|
||||
|
||||
|
@ -48,7 +51,8 @@ public:
|
|||
void SpawnDefaultWeapon();
|
||||
UPROPERTY()
|
||||
TMap<FName, class UBoxComponent*> HitCollisionBoxes;
|
||||
|
||||
|
||||
bool bFinishedSwapping = false;
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
|
@ -191,6 +195,9 @@ private:
|
|||
UPROPERTY(EditAnywhere, Category = Combat)
|
||||
class UAnimMontage* ThrowGrenadeMontage;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = Combat)
|
||||
class UAnimMontage* SwapMontage;
|
||||
|
||||
void HideCameraIfCharacterClose();
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
|
|
|
@ -241,20 +241,13 @@ void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip)
|
|||
|
||||
void UCombatComponent::SwapWeapons()
|
||||
{
|
||||
if (CombatState != ECombatState::ECS_Unoccupied) return;
|
||||
|
||||
AWeapon* TempWeapon = PrimaryWeapon;
|
||||
PrimaryWeapon = SecondaryWeapon;
|
||||
SecondaryWeapon = TempWeapon;
|
||||
|
||||
PrimaryWeapon->SetWeaponState(EWeaponState::EWS_Equipped);
|
||||
AttachActorToRightHand(PrimaryWeapon);
|
||||
PrimaryWeapon->SetHUDAmmo();
|
||||
UpdateCarriedAmmo();
|
||||
PlayEquipWeaponSound(PrimaryWeapon);
|
||||
if (CombatState != ECombatState::ECS_Unoccupied || Character == nullptr || !Character->HasAuthority()) return;
|
||||
|
||||
SecondaryWeapon->SetWeaponState(EWeaponState::EWS_EquippedSecondary);
|
||||
AttachActorToBackpack(SecondaryWeapon);
|
||||
Character->PlaySwapMontage();
|
||||
CombatState = ECombatState::ECS_SwappingWeapons;
|
||||
Character->bFinishedSwapping = false;
|
||||
|
||||
if (SecondaryWeapon) SecondaryWeapon->EnableCustomDepth(false);
|
||||
}
|
||||
|
||||
bool UCombatComponent::ShouldSwapWeapons()
|
||||
|
@ -421,6 +414,32 @@ void UCombatComponent::FinishedReloading()
|
|||
}
|
||||
}
|
||||
|
||||
void UCombatComponent::FinishedSwap()
|
||||
{
|
||||
if (Character && Character->HasAuthority())
|
||||
{
|
||||
CombatState = ECombatState::ECS_Unoccupied;
|
||||
}
|
||||
if (Character) Character->bFinishedSwapping = true;
|
||||
if (SecondaryWeapon) SecondaryWeapon->EnableCustomDepth(true);
|
||||
}
|
||||
|
||||
void UCombatComponent::FinishedSwapAttachWeapons()
|
||||
{
|
||||
AWeapon* TempWeapon = PrimaryWeapon;
|
||||
PrimaryWeapon = SecondaryWeapon;
|
||||
SecondaryWeapon = TempWeapon;
|
||||
|
||||
PrimaryWeapon->SetWeaponState(EWeaponState::EWS_Equipped);
|
||||
AttachActorToRightHand(PrimaryWeapon);
|
||||
PrimaryWeapon->SetHUDAmmo();
|
||||
UpdateCarriedAmmo();
|
||||
PlayEquipWeaponSound(PrimaryWeapon);
|
||||
|
||||
SecondaryWeapon->SetWeaponState(EWeaponState::EWS_EquippedSecondary);
|
||||
AttachActorToBackpack(SecondaryWeapon);
|
||||
}
|
||||
|
||||
void UCombatComponent::DropWeapons()
|
||||
{
|
||||
if (PrimaryWeapon) PrimaryWeapon->Dropped();
|
||||
|
@ -535,6 +554,12 @@ void UCombatComponent::OnRep_CombatState()
|
|||
ShowAttachedGrenade(true);
|
||||
}
|
||||
break;
|
||||
case ECombatState::ECS_SwappingWeapons:
|
||||
if (Character && !Character->IsLocallyControlled())
|
||||
{
|
||||
Character->PlaySwapMontage();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -790,9 +815,9 @@ bool UCombatComponent::CanFire()
|
|||
{
|
||||
if (PrimaryWeapon == nullptr) return false;
|
||||
if (PrimaryWeapon->IsEmpty()) return false;
|
||||
if (bLocallyReloading) return false;
|
||||
if (!bCanFire) return false;
|
||||
if (CombatState == ECombatState::ECS_Reloading && PrimaryWeapon->GetWeaponType() == EWeaponType::EWT_Shotgun) return true;
|
||||
if (bLocallyReloading) return false;
|
||||
return CombatState == ECombatState::ECS_Unoccupied;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,12 @@ public:
|
|||
void DropWeapons();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void FinishedReloading();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void FinishedSwap();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void FinishedSwapAttachWeapons();
|
||||
|
||||
void FireButtonPressed(bool bPressed);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ enum class ECombatState : uint8
|
|||
ECS_Unoccupied UMETA(DisplayName = "Unoccupied"),
|
||||
ECS_Reloading UMETA(DisplayName = "Reloading"),
|
||||
ECS_ThrowingGrenade UMETA(DisplayName = "Throwing Grenade"),
|
||||
ECS_SwappingWeapons UMETA(DisplayName = "Swapping Weapons"),
|
||||
|
||||
ECS_MAX UMETA(DisplayName = "DefaultMAX")
|
||||
};
|
||||
|
|
|
@ -240,7 +240,6 @@ void AWeapon::OnEquippedSecondary()
|
|||
WeaponMesh->SetEnableGravity(true);
|
||||
WeaponMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
|
||||
}
|
||||
EnableCustomDepth(true);
|
||||
if (WeaponMesh)
|
||||
{
|
||||
WeaponMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_TAN);
|
||||
|
|
Loading…
Reference in New Issue