diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 8895600..8a75d07 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Content/Blueprints/Weapon/BP_AssaultRifle.uasset b/Content/Blueprints/Weapon/BP_AssaultRifle.uasset index 9064d82..6d0a000 100644 Binary files a/Content/Blueprints/Weapon/BP_AssaultRifle.uasset and b/Content/Blueprints/Weapon/BP_AssaultRifle.uasset differ diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index 8a08089..31254be 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -72,9 +72,10 @@ public: void SetOverlappingWeapon(AWeapon* Weapon); bool IsWeaponEquipped(); bool IsAiming(); - FORCEINLINE float GetAO_Yaw() const { return AO_Yaw; }; - FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; }; + FORCEINLINE float GetAO_Yaw() const { return AO_Yaw; } + FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; } AWeapon* GetEquippedWeapon(); - FORCEINLINE ETurningInPlace GetTurningInPlace() const { return TurningInPlace; }; + FORCEINLINE ETurningInPlace GetTurningInPlace() const { return TurningInPlace; } FVector GetHitTarget() const; + FORCEINLINE UCameraComponent* GetFollowCamera() const { return FollowCamera; } }; diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index d1ff252..13a6d3b 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -7,6 +7,7 @@ #include "Blaster/HUD/BlasterHUD.h" #include "Blaster/PlayerController/BlasterPlayerController.h" #include "Blaster/Weapon/Weapon.h" +#include "Camera/CameraComponent.h" #include "Engine/SkeletalMeshSocket.h" #include "GameFramework/CharacterMovementComponent.h" #include "Kismet/GameplayStatics.h" @@ -35,20 +36,27 @@ void UCombatComponent::BeginPlay() if (Character) { Character->GetCharacterMovement()->MaxWalkSpeed = BaseWalkSpeed; + + if (Character->GetFollowCamera()) + { + DefaultFOV = Character->GetFollowCamera()->FieldOfView; + CurrentFOV = DefaultFOV; + } } } void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - - SetHUDCrosshairs(DeltaTime); - + if (Character && Character->IsLocallyControlled()) { FHitResult HitResult; TraceUnderCrosshairs(HitResult); HitTarget = HitResult.ImpactPoint; + + SetHUDCrosshairs(DeltaTime); + InterpFOV(DeltaTime); } } @@ -105,6 +113,24 @@ void UCombatComponent::SetHUDCrosshairs(float DeltaTime) } } +void UCombatComponent::InterpFOV(float DeltaTime) +{ + if (EquippedWeapon == nullptr) return; + + if (bAiming) + { + CurrentFOV = FMath::FInterpTo(CurrentFOV, EquippedWeapon->GetZoomedFOV(), DeltaTime, EquippedWeapon->GetZoomInterpSpeed()); + } + else + { + CurrentFOV = FMath::FInterpTo(CurrentFOV, DefaultFOV, DeltaTime, ZoomInterpSpeed); + } + if (Character && Character->GetFollowCamera()) + { + Character->GetFollowCamera()->SetFieldOfView(CurrentFOV); + } +} + void UCombatComponent::SetAiming(bool bIsAiming) { bAiming = bIsAiming; diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index d674704..bf5f7ea 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -63,12 +63,24 @@ private: bool bFireButtonPressed; - /* - * HUD and Crosshairs - */ - + //HUD and Crosshairs float CrosshairVelocityFactor; float CrosshairInAirFactor; + // Aiming and FOV + + // Field of view when not aiming; set to the camera's base FOV in BeginPlay + float DefaultFOV; + + UPROPERTY(EditAnywhere, Category = Combat) + float ZoomedFOV = 30.f; + + float CurrentFOV; + + UPROPERTY(EditAnywhere, Category = Combat) + float ZoomInterpSpeed = 20.f; + + void InterpFOV(float DeltaTime); + FVector HitTarget; }; diff --git a/Source/Blaster/Weapon/Weapon.h b/Source/Blaster/Weapon/Weapon.h index 2682438..5678664 100644 --- a/Source/Blaster/Weapon/Weapon.h +++ b/Source/Blaster/Weapon/Weapon.h @@ -43,6 +43,13 @@ public: UPROPERTY(EditAnywhere, Category= Crosshairs) class UTexture2D* CrosshairsBottom; + + // Zoom FOV while aiming + UPROPERTY(EditAnywhere) + float ZoomedFOV = 30.f; + + UPROPERTY(EditAnywhere) + float ZoomInterpSpeed = 20.f; protected: virtual void BeginPlay() override; @@ -92,4 +99,7 @@ public: void SetWeaponState(EWeaponState State); FORCEINLINE USphereComponent* GetAreaSphere() const { return AreaSphere; } FORCEINLINE USkeletalMeshComponent* GetWeaponMesh() const { return WeaponMesh; }; + FORCEINLINE float GetZoomedFOV() const { return ZoomedFOV; }; + FORCEINLINE float GetZoomInterpSpeed() const { return ZoomInterpSpeed; }; + };