fix: fixed linetrace after locking character pitch

Fixed linetrace, because it was follow only horizontal axis after locking character pitch.
Added empty GunBase class with BP revolver item.
This commit is contained in:
Kubson96 2025-03-15 13:48:39 +01:00
parent 7a47ee69bb
commit e70f96df2c
8 changed files with 73 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@ -26,26 +26,33 @@ void UShootingComponent::BeginPlay()
void UShootingComponent::Shoot()
{
if (CurrentAmmo == 0 || bIsReloading || !bCanShoot) return;
APawn* PawnOwner = Cast<APawn>(PlayerCharacter);
if (!PawnOwner || !PawnOwner->GetController()) return;
bCanShoot = false;
CurrentAmmo--;
FVector ViewLocation;
FRotator ViewRotation;
PawnOwner->GetController()->GetPlayerViewPoint(ViewLocation, ViewRotation);
FVector ForwardVector = ViewRotation.Vector();
FVector LineStart = PlayerCharacter->GetActorLocation();
FVector ForwardVector = PlayerCharacter->GetActorForwardVector();
FVector LineEnd = LineStart + (ForwardVector * MaxRange);
FHitResult HitResult;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(PlayerCharacter);
// Strza³
// Strza<EFBFBD>
bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, LineStart, LineEnd, ECC_Visibility, QueryParams);
if (bHit && HitResult.GetActor() && HitResult.GetActor()->Implements<UDamageable>())
{
IDamageable::Execute_TakeDamage(HitResult.GetActor(), DamageValue);
UE_LOG(LogTemp, Display, TEXT("Shoot. Ammo: %d/%d"), CurrentAmmo, MaxAmmo); // Docelowo tutaj wywo³anie UI aktualizuj¹ce stan ammo
UE_LOG(LogTemp, Display, TEXT("Shoot. Ammo: %d/%d"), CurrentAmmo, MaxAmmo); // Docelowo tutaj wywo<EFBFBD>anie UI aktualizuj<75>ce stan ammo
}
PlayerCharacter->GetWorldTimerManager().SetTimer(ShootCooldownTimer, this, &UShootingComponent::ResetFireCooldown, FireRateCooldown, false);
@ -71,7 +78,7 @@ void UShootingComponent::Reload()
CurrentAmmo = MaxAmmo;
PlayerCharacter->GetWorldTimerManager().SetTimer(ReloadTimer, this, &UShootingComponent::ReloadCompleted, ReloadTime, false);
UE_LOG(LogTemp, Display, TEXT("Reloaded. Ammo: %d/%d"), CurrentAmmo, MaxAmmo); // Docelowo tutaj wywo³anie UI aktualizuj¹ce stan ammo
UE_LOG(LogTemp, Display, TEXT("Reloaded. Ammo: %d/%d"), CurrentAmmo, MaxAmmo); // Docelowo tutaj wywo<EFBFBD>anie UI aktualizuj<75>ce stan ammo
}
void UShootingComponent::ResetFireCooldown()

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Items/GunBase.h"
// Sets default values
AGunBase::AGunBase()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AGunBase::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AGunBase::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@ -15,9 +15,16 @@ void UInteractionComponent::BeginPlay()
void UInteractionComponent::CheckForInteractable()
{
AActor* Owner = GetOwner();
APawn* PawnOwner = Cast<APawn>(Owner);
if (!PawnOwner || !PawnOwner->GetController()) return;
FVector ViewLocation;
FRotator ViewRotation;
PawnOwner->GetController()->GetPlayerViewPoint(ViewLocation, ViewRotation);
FVector ForwardVector = ViewRotation.Vector();
FVector LineStart = Owner->GetActorLocation();
FVector ForwardVector = Owner->GetActorForwardVector();
FVector LineEnd = LineStart + (ForwardVector * InteractionDistance);
FHitResult HitResult;

View File

@ -0,0 +1,26 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "GunBase.generated.h"
UCLASS()
class EXO_API AGunBase : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AGunBase();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};

View File

@ -16,7 +16,7 @@ public:
UInteractionComponent();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Settings")
float InteractionDistance = 100.0f;
float InteractionDistance = 135.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Debug")
bool bShowDebugLine = false;