diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 8a75d07..c020484 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/BlasterAnimInstance.cpp b/Source/Blaster/Character/BlasterAnimInstance.cpp index 9119c50..5e75a17 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.cpp +++ b/Source/Blaster/Character/BlasterAnimInstance.cpp @@ -69,7 +69,8 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) { bLocallyControlled = true; const FTransform RightHandTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("Hand_R"), RTS_World); - RightHandRotation = UKismetMathLibrary::FindLookAtRotation(RightHandTransform.GetLocation(), RightHandTransform.GetLocation() + (RightHandTransform.GetLocation() - BlasterCharacter->GetHitTarget())); + FRotator LookAtRotation = UKismetMathLibrary::FindLookAtRotation(RightHandTransform.GetLocation(), RightHandTransform.GetLocation() + (RightHandTransform.GetLocation() - BlasterCharacter->GetHitTarget())); + RightHandRotation = FMath::RInterpTo(RightHandRotation, LookAtRotation, DeltaSeconds, 30.f); } } } diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 2f07e21..748b7b1 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -34,11 +34,12 @@ ABlasterCharacter::ABlasterCharacter() OverheadWidget->SetupAttachment(RootComponent); Combat = CreateDefaultSubobject(TEXT("CombatComponent")); - Combat->SetIsReplicated(true); + Combat->SetIsReplicatedByDefault(true); GetCharacterMovement()->NavAgentProps.bCanCrouch = true; - GetCapsuleComponent()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore); - GetMesh()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore); + GetCapsuleComponent()->SetCollisionResponseToChannel(ECC_Camera, ECR_Ignore); + GetMesh()->SetCollisionResponseToChannel(ECC_Camera, ECR_Ignore); + GetMesh()->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block); GetCharacterMovement()->RotationRate = FRotator(0.f, 850.f, 0.f); TurningInPlace = ETurningInPlace::ETIP_NotTurning; NetUpdateFrequency = 66.f; diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index 31254be..5408e32 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -3,12 +3,13 @@ #pragma once #include "CoreMinimal.h" +#include "Blaster/Interfaces/InteractWithCrosshairInterface.h" #include "Blaster/Types/TurningInPlace.h" #include "GameFramework/Character.h" #include "BlasterCharacter.generated.h" UCLASS() -class BLASTER_API ABlasterCharacter : public ACharacter +class BLASTER_API ABlasterCharacter : public ACharacter, public IInteractWithCrosshairInterface { GENERATED_BODY() diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 9d7bffd..a67db98 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -4,7 +4,6 @@ #include "CombatComponent.h" #include "Blaster/Character/BlasterCharacter.h" -#include "Blaster/HUD/BlasterHUD.h" #include "Blaster/PlayerController/BlasterPlayerController.h" #include "Blaster/Weapon/Weapon.h" #include "Camera/CameraComponent.h" @@ -48,7 +47,7 @@ void UCombatComponent::BeginPlay() void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - + if (Character && Character->IsLocallyControlled()) { FHitResult HitResult; @@ -70,8 +69,6 @@ void UCombatComponent::SetHUDCrosshairs(float DeltaTime) HUD = HUD == nullptr ? Cast(Controller->GetHUD()) : HUD; if (HUD) { - FHUDPackage HUDPackage; - if (EquippedWeapon) { HUDPackage.CrosshairsCenter = EquippedWeapon->CrosshairsCenter; @@ -97,7 +94,7 @@ void UCombatComponent::SetHUDCrosshairs(float DeltaTime) Velocity.Z = 0.f; CrosshairVelocityFactor = FMath::GetMappedRangeValueClamped(WalkSpeedRange, VelocityMultiplierRange, Velocity.Size()); - + if (Character->GetCharacterMovement()->IsFalling()) { CrosshairInAirFactor = FMath::FInterpTo(CrosshairInAirFactor, 2.25f, DeltaTime, 2.25f); @@ -117,14 +114,14 @@ void UCombatComponent::SetHUDCrosshairs(float DeltaTime) } CrosshairShootingFactor = FMath::FInterpTo(CrosshairShootingFactor, 0.f, DeltaTime, 40.f); - + HUDPackage.CrosshairSpread = - 0.5f + - CrosshairVelocityFactor + - CrosshairInAirFactor - - CrosshairAimFactor + - CrosshairShootingFactor; - + 0.5f + + CrosshairVelocityFactor + + CrosshairInAirFactor - + CrosshairAimFactor + + CrosshairShootingFactor; + HUD->SetHUDPackage(HUDPackage); } } @@ -222,8 +219,16 @@ void UCombatComponent::TraceUnderCrosshairs(FHitResult& TraceHitResult) End, ECollisionChannel::ECC_Visibility ); + if (TraceHitResult.GetActor() && TraceHitResult.GetActor()->Implements()) + { + HUDPackage.CrosshairColor = FLinearColor::Red; + } + else + { + HUDPackage.CrosshairColor = FLinearColor::White; + } - if (!TraceHitResult.bBlockingHit) TraceHitResult.ImpactPoint = End; + if (!TraceHitResult.bBlockingHit) TraceHitResult.ImpactPoint = End; } } diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index a289baa..51a0b12 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "Blaster/HUD/BlasterHUD.h" #include "Components/ActorComponent.h" #include "CombatComponent.generated.h" @@ -68,7 +69,8 @@ private: float CrosshairInAirFactor; float CrosshairAimFactor; float CrosshairShootingFactor; - + FHUDPackage HUDPackage; + // Aiming and FOV // Field of view when not aiming; set to the camera's base FOV in BeginPlay diff --git a/Source/Blaster/HUD/BlasterHUD.cpp b/Source/Blaster/HUD/BlasterHUD.cpp index 92d1b3d..5e0731a 100644 --- a/Source/Blaster/HUD/BlasterHUD.cpp +++ b/Source/Blaster/HUD/BlasterHUD.cpp @@ -17,32 +17,32 @@ void ABlasterHUD::DrawHUD() if (HUDPackage.CrosshairsCenter) { const FVector2D Spread(0.f, 0.f); - DrawCrosshair(HUDPackage.CrosshairsCenter, ViewportCenter, Spread); + DrawCrosshair(HUDPackage.CrosshairsCenter, ViewportCenter, Spread, HUDPackage.CrosshairColor); } if (HUDPackage.CrosshairsLeft) { const FVector2D Spread(-SpreadScaled, 0.f); - DrawCrosshair(HUDPackage.CrosshairsLeft, ViewportCenter, Spread); + DrawCrosshair(HUDPackage.CrosshairsLeft, ViewportCenter, Spread, HUDPackage.CrosshairColor); } if (HUDPackage.CrosshairsRight) { const FVector2D Spread(SpreadScaled, 0.f); - DrawCrosshair(HUDPackage.CrosshairsRight, ViewportCenter, Spread); + DrawCrosshair(HUDPackage.CrosshairsRight, ViewportCenter, Spread, HUDPackage.CrosshairColor); } if (HUDPackage.CrosshairsTop) { const FVector2D Spread(0.f, -SpreadScaled); - DrawCrosshair(HUDPackage.CrosshairsTop, ViewportCenter, Spread); + DrawCrosshair(HUDPackage.CrosshairsTop, ViewportCenter, Spread, HUDPackage.CrosshairColor); } if (HUDPackage.CrosshairsBottom) { const FVector2D Spread(0.f, SpreadScaled); - DrawCrosshair(HUDPackage.CrosshairsBottom, ViewportCenter, Spread); + DrawCrosshair(HUDPackage.CrosshairsBottom, ViewportCenter, Spread, HUDPackage.CrosshairColor); } } } -void ABlasterHUD::DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread) +void ABlasterHUD::DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread, FLinearColor CrosshairColor) { const float TextureWidth = Texture->GetSizeX(); const float TextureHeight = Texture->GetSizeY(); @@ -61,6 +61,6 @@ void ABlasterHUD::DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, F 0.f, 1.f, 1.f, - FLinearColor::White + CrosshairColor ); } diff --git a/Source/Blaster/HUD/BlasterHUD.h b/Source/Blaster/HUD/BlasterHUD.h index c36dcd2..ab0f45f 100644 --- a/Source/Blaster/HUD/BlasterHUD.h +++ b/Source/Blaster/HUD/BlasterHUD.h @@ -18,6 +18,7 @@ public: UTexture2D* CrosshairsTop; UTexture2D* CrosshairsBottom; float CrosshairSpread; + FLinearColor CrosshairColor; }; /** @@ -34,7 +35,7 @@ public: private: FHUDPackage HUDPackage; - void DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread); + void DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread, FLinearColor CrosshairColor); UPROPERTY(EditAnywhere) float CrosshairSpreadMax = 16.f; diff --git a/Source/Blaster/Interfaces/InteractWithCrosshairInterface.cpp b/Source/Blaster/Interfaces/InteractWithCrosshairInterface.cpp new file mode 100644 index 0000000..0b97038 --- /dev/null +++ b/Source/Blaster/Interfaces/InteractWithCrosshairInterface.cpp @@ -0,0 +1,6 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "InteractWithCrosshairInterface.h" + +// Add default functionality here for any IInteractWithCrosshairInterface functions that are not pure virtual. diff --git a/Source/Blaster/Interfaces/InteractWithCrosshairInterface.h b/Source/Blaster/Interfaces/InteractWithCrosshairInterface.h new file mode 100644 index 0000000..17d9211 --- /dev/null +++ b/Source/Blaster/Interfaces/InteractWithCrosshairInterface.h @@ -0,0 +1,25 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "UObject/Interface.h" +#include "InteractWithCrosshairInterface.generated.h" + +// This class does not need to be modified. +UINTERFACE(MinimalAPI) +class UInteractWithCrosshairInterface : public UInterface +{ + GENERATED_BODY() +}; + +/** + * + */ +class BLASTER_API IInteractWithCrosshairInterface +{ + GENERATED_BODY() + + // Add interface functions to this class. This is the class that will be inherited to implement this interface. +public: +};