diff --git a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset index fdc8d4c..379559b 100644 Binary files a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset and b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset differ diff --git a/Content/Blueprints/Items/RevolverGun.uasset b/Content/Blueprints/Items/RevolverGun.uasset new file mode 100644 index 0000000..9ce83b1 Binary files /dev/null and b/Content/Blueprints/Items/RevolverGun.uasset differ diff --git a/Content/Levels/TestMap.umap b/Content/Levels/TestMap.umap index 25f5e19..fb68d38 100644 Binary files a/Content/Levels/TestMap.umap and b/Content/Levels/TestMap.umap differ diff --git a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp index 1945e58..28d4447 100644 --- a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp +++ b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp @@ -26,26 +26,33 @@ void UShootingComponent::BeginPlay() void UShootingComponent::Shoot() { if (CurrentAmmo == 0 || bIsReloading || !bCanShoot) return; + + APawn* PawnOwner = Cast(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� bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, LineStart, LineEnd, ECC_Visibility, QueryParams); if (bHit && HitResult.GetActor() && HitResult.GetActor()->Implements()) { 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�anie UI aktualizuj�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�anie UI aktualizuj�ce stan ammo } void UShootingComponent::ResetFireCooldown() diff --git a/Source/Exo/Private/Items/GunBase.cpp b/Source/Exo/Private/Items/GunBase.cpp new file mode 100644 index 0000000..8d66773 --- /dev/null +++ b/Source/Exo/Private/Items/GunBase.cpp @@ -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); + +} + diff --git a/Source/Exo/Private/Player/InteractionComponent.cpp b/Source/Exo/Private/Player/InteractionComponent.cpp index 2344ce4..0b01ae0 100644 --- a/Source/Exo/Private/Player/InteractionComponent.cpp +++ b/Source/Exo/Private/Player/InteractionComponent.cpp @@ -15,9 +15,16 @@ void UInteractionComponent::BeginPlay() void UInteractionComponent::CheckForInteractable() { AActor* Owner = GetOwner(); + APawn* PawnOwner = Cast(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; diff --git a/Source/Exo/Public/Items/GunBase.h b/Source/Exo/Public/Items/GunBase.h new file mode 100644 index 0000000..b5c1f97 --- /dev/null +++ b/Source/Exo/Public/Items/GunBase.h @@ -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; + +}; diff --git a/Source/Exo/Public/Player/InteractionComponent.h b/Source/Exo/Public/Player/InteractionComponent.h index a8b7a07..ad8656a 100644 --- a/Source/Exo/Public/Player/InteractionComponent.h +++ b/Source/Exo/Public/Player/InteractionComponent.h @@ -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;