diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index fb7ccca..a0e2f78 100644 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -77,6 +77,7 @@ DoubleClickTime=0.200000 +ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=SpaceBar) +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) +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/Blueprints/Character/Animation/BlasterAnimBP.uasset b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset index 49f724f..286021b 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 00f5385..20866f9 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.cpp +++ b/Source/Blaster/Character/BlasterAnimInstance.cpp @@ -32,4 +32,5 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) bIsAccelerating = BlasterCharacter->GetCharacterMovement()->GetCurrentAcceleration().Size() > 0.f; bWeaponEquipped = BlasterCharacter->IsWeaponEquipped(); bIsCrouched = BlasterCharacter->bIsCrouched; + bAiming = BlasterCharacter->IsAiming(); } diff --git a/Source/Blaster/Character/BlasterAnimInstance.h b/Source/Blaster/Character/BlasterAnimInstance.h index 58a3764..37b3c11 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.h +++ b/Source/Blaster/Character/BlasterAnimInstance.h @@ -38,4 +38,7 @@ private: UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) bool bIsCrouched; + + UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) + bool bAiming; }; diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 4fc45d9..3d336ab 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -71,6 +71,8 @@ void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCo PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump); PlayerInputComponent->BindAction("Equip", IE_Pressed, this, &ABlasterCharacter::EquipButtonPressed); 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->BindAxis("MoveForward", this, &ABlasterCharacter::MoveForward); PlayerInputComponent->BindAxis("MoveRight", this, &ABlasterCharacter::MoveRight); @@ -137,6 +139,22 @@ void ABlasterCharacter::CrouchButtonPressed() } } +void ABlasterCharacter::AimButtonPressed() +{ + if (Combat) + { + Combat->SetAiming(true); + } +} + +void ABlasterCharacter::AimButtonReleased() +{ + if (Combat) + { + Combat->SetAiming(false); + } +} + void ABlasterCharacter::ServerEquipButtonPressed_Implementation() { EquipButtonPressed(); @@ -164,6 +182,11 @@ bool ABlasterCharacter::IsWeaponEquipped() return Combat && Combat->EquippedWeapon; } +bool ABlasterCharacter::IsAiming() +{ + return Combat && Combat->bAiming; +} + void ABlasterCharacter::OnRep_OverlappingWeapon(AWeapon* LastWeapon) { if (OverlappingWeapon) diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index d6427bd..bd2c233 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -27,6 +27,8 @@ protected: void LookUp(float Value); void EquipButtonPressed(); void CrouchButtonPressed(); + void AimButtonPressed(); + void AimButtonReleased(); private: UPROPERTY(VisibleAnywhere, Category="Camera") @@ -52,4 +54,5 @@ private: public: void SetOverlappingWeapon(AWeapon* Weapon); bool IsWeaponEquipped(); + bool IsAiming(); }; diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 7070f81..19f3cf6 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -18,6 +18,17 @@ void UCombatComponent::BeginPlay() Super::BeginPlay(); } +void UCombatComponent::SetAiming(bool bIsAiming) +{ + bAiming = bIsAiming; + ServerSetAiming(bIsAiming); +} + +void UCombatComponent::ServerSetAiming_Implementation(bool bIsAiming) +{ + bAiming = bIsAiming; +} + void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); @@ -29,6 +40,7 @@ void UCombatComponent::GetLifetimeReplicatedProps(TArray& Out Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(UCombatComponent, EquippedWeapon); + DOREPLIFETIME(UCombatComponent, bAiming); } void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip) diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index 1cb5281..23f52e9 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -23,10 +23,17 @@ public: protected: virtual void BeginPlay() override; + void SetAiming(bool bIsAiming); + + UFUNCTION(Server, Reliable) + void ServerSetAiming(bool bIsAiming); private: class ABlasterCharacter* Character; UPROPERTY(Replicated) class AWeapon* EquippedWeapon; + + UPROPERTY(Replicated) + bool bAiming; };