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