86 - Change Crosshair Color

This commit is contained in:
Kingsmedia 2022-05-05 22:46:35 +02:00
parent dff53980f9
commit eeb7113a38
10 changed files with 69 additions and 27 deletions

View File

@ -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);
}
}
}

View File

@ -34,11 +34,12 @@ ABlasterCharacter::ABlasterCharacter()
OverheadWidget->SetupAttachment(RootComponent);
Combat = CreateDefaultSubobject<UCombatComponent>(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;

View File

@ -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()

View File

@ -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"
@ -70,8 +69,6 @@ void UCombatComponent::SetHUDCrosshairs(float DeltaTime)
HUD = HUD == nullptr ? Cast<ABlasterHUD>(Controller->GetHUD()) : HUD;
if (HUD)
{
FHUDPackage HUDPackage;
if (EquippedWeapon)
{
HUDPackage.CrosshairsCenter = EquippedWeapon->CrosshairsCenter;
@ -222,6 +219,14 @@ void UCombatComponent::TraceUnderCrosshairs(FHitResult& TraceHitResult)
End,
ECollisionChannel::ECC_Visibility
);
if (TraceHitResult.GetActor() && TraceHitResult.GetActor()->Implements<UInteractWithCrosshairInterface>())
{
HUDPackage.CrosshairColor = FLinearColor::Red;
}
else
{
HUDPackage.CrosshairColor = FLinearColor::White;
}
if (!TraceHitResult.bBlockingHit) TraceHitResult.ImpactPoint = End;
}

View File

@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "Blaster/HUD/BlasterHUD.h"
#include "Components/ActorComponent.h"
#include "CombatComponent.generated.h"
@ -68,6 +69,7 @@ private:
float CrosshairInAirFactor;
float CrosshairAimFactor;
float CrosshairShootingFactor;
FHUDPackage HUDPackage;
// Aiming and FOV

View File

@ -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
);
}

View File

@ -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;

View File

@ -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.

View File

@ -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:
};