diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index a0e2f78..19da539 100644 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -78,6 +78,7 @@ DoubleClickTime=0.200000 +ActionMappings=(ActionName="Equip",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=E) +ActionMappings=(ActionName="Crouch",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftControl) +ActionMappings=(ActionName="Aim",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=RightMouseButton) ++ActionMappings=(ActionName="Fire",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftMouseButton) +AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=W) +AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=S) +AxisMappings=(AxisName="MoveRight",Scale=1.000000,Key=D) diff --git a/Content/Assets/Animations/Fire_Rifle_Hip.uasset b/Content/Assets/Animations/Fire_Rifle_Hip.uasset index 1e43a6e..350fbdb 100644 Binary files a/Content/Assets/Animations/Fire_Rifle_Hip.uasset and b/Content/Assets/Animations/Fire_Rifle_Hip.uasset differ diff --git a/Content/Assets/Animations/Fire_Rifle_Ironsights.uasset b/Content/Assets/Animations/Fire_Rifle_Ironsights.uasset index 2561773..72e7e29 100644 Binary files a/Content/Assets/Animations/Fire_Rifle_Ironsights.uasset and b/Content/Assets/Animations/Fire_Rifle_Ironsights.uasset differ diff --git a/Content/Assets/LearningKit_Games/Assets/Characters/Character/Mesh/SK_EpicCharacter_Skeleton.uasset b/Content/Assets/LearningKit_Games/Assets/Characters/Character/Mesh/SK_EpicCharacter_Skeleton.uasset index b47c7c7..f53a962 100644 Binary files a/Content/Assets/LearningKit_Games/Assets/Characters/Character/Mesh/SK_EpicCharacter_Skeleton.uasset and b/Content/Assets/LearningKit_Games/Assets/Characters/Character/Mesh/SK_EpicCharacter_Skeleton.uasset differ diff --git a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset index 66f7936..6a0cfe4 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/FireWeapon.uasset b/Content/Blueprints/Character/Animation/FireWeapon.uasset new file mode 100644 index 0000000..29a9966 Binary files /dev/null and b/Content/Blueprints/Character/Animation/FireWeapon.uasset differ diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 42c4dda..8d48531 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/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 932891f..8c7a501 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -62,6 +62,19 @@ void ABlasterCharacter::PostInitializeComponents() } } +void ABlasterCharacter::PlayFireMontage(bool bAiming) +{ + if (Combat == nullptr || Combat->EquippedWeapon == nullptr) return; + + UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); + if (AnimInstance && FireWeaponMontage) + { + AnimInstance->Montage_Play(FireWeaponMontage); + FName SectionName = bAiming ? FName("RifleADS") : FName("RifleHip"); + AnimInstance->Montage_JumpToSection(SectionName); + } +} + void ABlasterCharacter::BeginPlay() { Super::BeginPlay(); @@ -83,6 +96,8 @@ void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCo PlayerInputComponent->BindAction("Crouch", IE_Pressed, this, &ABlasterCharacter::CrouchButtonPressed); PlayerInputComponent->BindAction("Aim", IE_Pressed, this, &ABlasterCharacter::AimButtonPressed); PlayerInputComponent->BindAction("Aim", IE_Released, this, &ABlasterCharacter::AimButtonReleased); + PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &ABlasterCharacter::FireButtonPressed); + PlayerInputComponent->BindAction("Fire", IE_Released, this, &ABlasterCharacter::FireButtonReleased); PlayerInputComponent->BindAxis("MoveForward", this, &ABlasterCharacter::MoveForward); PlayerInputComponent->BindAxis("MoveRight", this, &ABlasterCharacter::MoveRight); @@ -218,6 +233,22 @@ void ABlasterCharacter::Jump() } } +void ABlasterCharacter::FireButtonPressed() +{ + if (Combat) + { + Combat->FireButtonPressed(true); + } +} + +void ABlasterCharacter::FireButtonReleased() +{ + if (Combat) + { + Combat->FireButtonPressed(false); + } +} + void ABlasterCharacter::ServerEquipButtonPressed_Implementation() { EquipButtonPressed(); diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index 2a1ee1b..bb6cf57 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -18,6 +18,7 @@ public: virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; virtual void PostInitializeComponents() override; + void PlayFireMontage(bool bAiming); protected: virtual void BeginPlay() override; @@ -32,6 +33,8 @@ protected: void AimButtonReleased(); void AimOffset(float DeltaTime); virtual void Jump() override; + void FireButtonPressed(); + void FireButtonReleased(); private: UPROPERTY(VisibleAnywhere, Category="Camera") @@ -62,6 +65,9 @@ private: ETurningInPlace TurningInPlace; void TurnInPlace(float DeltaTime); + + UPROPERTY(EditAnywhere, Category = Combat) + class UAnimMontage* FireWeaponMontage; public: void SetOverlappingWeapon(AWeapon* Weapon); bool IsWeaponEquipped(); diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 6ee8fbd..31abfc0 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -55,6 +55,15 @@ void UCombatComponent::OnRep_EquippedWeapon() } } +void UCombatComponent::FireButtonPressed(bool bPressed) +{ + bFireButtonPressed = bPressed; + if (Character && bFireButtonPressed) + { + Character->PlayFireMontage(bAiming); + } +} + void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index 7bf4d7f..f6bec73 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -31,6 +31,8 @@ protected: UFUNCTION() void OnRep_EquippedWeapon(); + void FireButtonPressed(bool bPressed); + private: class ABlasterCharacter* Character; @@ -45,4 +47,6 @@ private: UPROPERTY(EditAnywhere) float AimWalkSpeed; + + bool bFireButtonPressed; };