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:
parent
7a47ee69bb
commit
e70f96df2c
Binary file not shown.
BIN
Content/Blueprints/Items/RevolverGun.uasset
Normal file
BIN
Content/Blueprints/Items/RevolverGun.uasset
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -27,25 +27,32 @@ 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()
|
||||
|
|
|
|||
27
Source/Exo/Private/Items/GunBase.cpp
Normal file
27
Source/Exo/Private/Items/GunBase.cpp
Normal 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);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
26
Source/Exo/Public/Items/GunBase.h
Normal file
26
Source/Exo/Public/Items/GunBase.h
Normal 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;
|
||||
|
||||
};
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user