86 - Change Crosshair Color
This commit is contained in:
parent
dff53980f9
commit
eeb7113a38
Binary file not shown.
|
@ -69,7 +69,8 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
|
||||||
{
|
{
|
||||||
bLocallyControlled = true;
|
bLocallyControlled = true;
|
||||||
const FTransform RightHandTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("Hand_R"), RTS_World);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,12 @@ ABlasterCharacter::ABlasterCharacter()
|
||||||
OverheadWidget->SetupAttachment(RootComponent);
|
OverheadWidget->SetupAttachment(RootComponent);
|
||||||
|
|
||||||
Combat = CreateDefaultSubobject<UCombatComponent>(TEXT("CombatComponent"));
|
Combat = CreateDefaultSubobject<UCombatComponent>(TEXT("CombatComponent"));
|
||||||
Combat->SetIsReplicated(true);
|
Combat->SetIsReplicatedByDefault(true);
|
||||||
|
|
||||||
GetCharacterMovement()->NavAgentProps.bCanCrouch = true;
|
GetCharacterMovement()->NavAgentProps.bCanCrouch = true;
|
||||||
GetCapsuleComponent()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore);
|
GetCapsuleComponent()->SetCollisionResponseToChannel(ECC_Camera, ECR_Ignore);
|
||||||
GetMesh()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore);
|
GetMesh()->SetCollisionResponseToChannel(ECC_Camera, ECR_Ignore);
|
||||||
|
GetMesh()->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
|
||||||
GetCharacterMovement()->RotationRate = FRotator(0.f, 850.f, 0.f);
|
GetCharacterMovement()->RotationRate = FRotator(0.f, 850.f, 0.f);
|
||||||
TurningInPlace = ETurningInPlace::ETIP_NotTurning;
|
TurningInPlace = ETurningInPlace::ETIP_NotTurning;
|
||||||
NetUpdateFrequency = 66.f;
|
NetUpdateFrequency = 66.f;
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blaster/Interfaces/InteractWithCrosshairInterface.h"
|
||||||
#include "Blaster/Types/TurningInPlace.h"
|
#include "Blaster/Types/TurningInPlace.h"
|
||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "BlasterCharacter.generated.h"
|
#include "BlasterCharacter.generated.h"
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class BLASTER_API ABlasterCharacter : public ACharacter
|
class BLASTER_API ABlasterCharacter : public ACharacter, public IInteractWithCrosshairInterface
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "CombatComponent.h"
|
#include "CombatComponent.h"
|
||||||
|
|
||||||
#include "Blaster/Character/BlasterCharacter.h"
|
#include "Blaster/Character/BlasterCharacter.h"
|
||||||
#include "Blaster/HUD/BlasterHUD.h"
|
|
||||||
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
||||||
#include "Blaster/Weapon/Weapon.h"
|
#include "Blaster/Weapon/Weapon.h"
|
||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
|
@ -48,7 +47,7 @@ void UCombatComponent::BeginPlay()
|
||||||
void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||||
{
|
{
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
|
||||||
if (Character && Character->IsLocallyControlled())
|
if (Character && Character->IsLocallyControlled())
|
||||||
{
|
{
|
||||||
FHitResult HitResult;
|
FHitResult HitResult;
|
||||||
|
@ -70,8 +69,6 @@ void UCombatComponent::SetHUDCrosshairs(float DeltaTime)
|
||||||
HUD = HUD == nullptr ? Cast<ABlasterHUD>(Controller->GetHUD()) : HUD;
|
HUD = HUD == nullptr ? Cast<ABlasterHUD>(Controller->GetHUD()) : HUD;
|
||||||
if (HUD)
|
if (HUD)
|
||||||
{
|
{
|
||||||
FHUDPackage HUDPackage;
|
|
||||||
|
|
||||||
if (EquippedWeapon)
|
if (EquippedWeapon)
|
||||||
{
|
{
|
||||||
HUDPackage.CrosshairsCenter = EquippedWeapon->CrosshairsCenter;
|
HUDPackage.CrosshairsCenter = EquippedWeapon->CrosshairsCenter;
|
||||||
|
@ -97,7 +94,7 @@ void UCombatComponent::SetHUDCrosshairs(float DeltaTime)
|
||||||
Velocity.Z = 0.f;
|
Velocity.Z = 0.f;
|
||||||
|
|
||||||
CrosshairVelocityFactor = FMath::GetMappedRangeValueClamped(WalkSpeedRange, VelocityMultiplierRange, Velocity.Size());
|
CrosshairVelocityFactor = FMath::GetMappedRangeValueClamped(WalkSpeedRange, VelocityMultiplierRange, Velocity.Size());
|
||||||
|
|
||||||
if (Character->GetCharacterMovement()->IsFalling())
|
if (Character->GetCharacterMovement()->IsFalling())
|
||||||
{
|
{
|
||||||
CrosshairInAirFactor = FMath::FInterpTo(CrosshairInAirFactor, 2.25f, DeltaTime, 2.25f);
|
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);
|
CrosshairShootingFactor = FMath::FInterpTo(CrosshairShootingFactor, 0.f, DeltaTime, 40.f);
|
||||||
|
|
||||||
HUDPackage.CrosshairSpread =
|
HUDPackage.CrosshairSpread =
|
||||||
0.5f +
|
0.5f +
|
||||||
CrosshairVelocityFactor +
|
CrosshairVelocityFactor +
|
||||||
CrosshairInAirFactor -
|
CrosshairInAirFactor -
|
||||||
CrosshairAimFactor +
|
CrosshairAimFactor +
|
||||||
CrosshairShootingFactor;
|
CrosshairShootingFactor;
|
||||||
|
|
||||||
HUD->SetHUDPackage(HUDPackage);
|
HUD->SetHUDPackage(HUDPackage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,8 +219,16 @@ void UCombatComponent::TraceUnderCrosshairs(FHitResult& TraceHitResult)
|
||||||
End,
|
End,
|
||||||
ECollisionChannel::ECC_Visibility
|
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;
|
if (!TraceHitResult.bBlockingHit) TraceHitResult.ImpactPoint = End;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blaster/HUD/BlasterHUD.h"
|
||||||
#include "Components/ActorComponent.h"
|
#include "Components/ActorComponent.h"
|
||||||
#include "CombatComponent.generated.h"
|
#include "CombatComponent.generated.h"
|
||||||
|
|
||||||
|
@ -68,7 +69,8 @@ private:
|
||||||
float CrosshairInAirFactor;
|
float CrosshairInAirFactor;
|
||||||
float CrosshairAimFactor;
|
float CrosshairAimFactor;
|
||||||
float CrosshairShootingFactor;
|
float CrosshairShootingFactor;
|
||||||
|
FHUDPackage HUDPackage;
|
||||||
|
|
||||||
// Aiming and FOV
|
// Aiming and FOV
|
||||||
|
|
||||||
// Field of view when not aiming; set to the camera's base FOV in BeginPlay
|
// Field of view when not aiming; set to the camera's base FOV in BeginPlay
|
||||||
|
|
|
@ -17,32 +17,32 @@ void ABlasterHUD::DrawHUD()
|
||||||
if (HUDPackage.CrosshairsCenter)
|
if (HUDPackage.CrosshairsCenter)
|
||||||
{
|
{
|
||||||
const FVector2D Spread(0.f, 0.f);
|
const FVector2D Spread(0.f, 0.f);
|
||||||
DrawCrosshair(HUDPackage.CrosshairsCenter, ViewportCenter, Spread);
|
DrawCrosshair(HUDPackage.CrosshairsCenter, ViewportCenter, Spread, HUDPackage.CrosshairColor);
|
||||||
}
|
}
|
||||||
if (HUDPackage.CrosshairsLeft)
|
if (HUDPackage.CrosshairsLeft)
|
||||||
{
|
{
|
||||||
const FVector2D Spread(-SpreadScaled, 0.f);
|
const FVector2D Spread(-SpreadScaled, 0.f);
|
||||||
DrawCrosshair(HUDPackage.CrosshairsLeft, ViewportCenter, Spread);
|
DrawCrosshair(HUDPackage.CrosshairsLeft, ViewportCenter, Spread, HUDPackage.CrosshairColor);
|
||||||
}
|
}
|
||||||
if (HUDPackage.CrosshairsRight)
|
if (HUDPackage.CrosshairsRight)
|
||||||
{
|
{
|
||||||
const FVector2D Spread(SpreadScaled, 0.f);
|
const FVector2D Spread(SpreadScaled, 0.f);
|
||||||
DrawCrosshair(HUDPackage.CrosshairsRight, ViewportCenter, Spread);
|
DrawCrosshair(HUDPackage.CrosshairsRight, ViewportCenter, Spread, HUDPackage.CrosshairColor);
|
||||||
}
|
}
|
||||||
if (HUDPackage.CrosshairsTop)
|
if (HUDPackage.CrosshairsTop)
|
||||||
{
|
{
|
||||||
const FVector2D Spread(0.f, -SpreadScaled);
|
const FVector2D Spread(0.f, -SpreadScaled);
|
||||||
DrawCrosshair(HUDPackage.CrosshairsTop, ViewportCenter, Spread);
|
DrawCrosshair(HUDPackage.CrosshairsTop, ViewportCenter, Spread, HUDPackage.CrosshairColor);
|
||||||
}
|
}
|
||||||
if (HUDPackage.CrosshairsBottom)
|
if (HUDPackage.CrosshairsBottom)
|
||||||
{
|
{
|
||||||
const FVector2D Spread(0.f, SpreadScaled);
|
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 TextureWidth = Texture->GetSizeX();
|
||||||
const float TextureHeight = Texture->GetSizeY();
|
const float TextureHeight = Texture->GetSizeY();
|
||||||
|
@ -61,6 +61,6 @@ void ABlasterHUD::DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, F
|
||||||
0.f,
|
0.f,
|
||||||
1.f,
|
1.f,
|
||||||
1.f,
|
1.f,
|
||||||
FLinearColor::White
|
CrosshairColor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
UTexture2D* CrosshairsTop;
|
UTexture2D* CrosshairsTop;
|
||||||
UTexture2D* CrosshairsBottom;
|
UTexture2D* CrosshairsBottom;
|
||||||
float CrosshairSpread;
|
float CrosshairSpread;
|
||||||
|
FLinearColor CrosshairColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +35,7 @@ public:
|
||||||
private:
|
private:
|
||||||
FHUDPackage HUDPackage;
|
FHUDPackage HUDPackage;
|
||||||
|
|
||||||
void DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread);
|
void DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread, FLinearColor CrosshairColor);
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
float CrosshairSpreadMax = 16.f;
|
float CrosshairSpreadMax = 16.f;
|
||||||
|
|
|
@ -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.
|
|
@ -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:
|
||||||
|
};
|
Loading…
Reference in New Issue