diff --git a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp index 8b850c3..948c86f 100644 --- a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp +++ b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp @@ -3,6 +3,8 @@ #include "Characters/Components/ShootingComponent.h" +#include "KismetTraceUtils.h" + // Sets default values for this component's properties UShootingComponent::UShootingComponent() { @@ -38,7 +40,7 @@ void UShootingComponent::Shoot() PawnOwner->GetController()->GetPlayerViewPoint(ViewLocation, ViewRotation); FVector ForwardVector = ViewRotation.Vector(); - FVector LineStart = PlayerCharacter->GetActorLocation(); + FVector LineStart = ViewLocation; //PlayerCharacter->GetActorLocation(); FVector LineEnd = LineStart + (ForwardVector * MaxRange); FHitResult HitResult; @@ -50,7 +52,7 @@ void UShootingComponent::Shoot() if (bHit && HitResult.GetActor() && HitResult.GetActor()->Implements()) { - IDamageable::Execute_TakeDamage(HitResult.GetActor(), DamageValue); + IDamageable::Execute_TakeDamage(HitResult.GetActor(), FireDamageValue); UE_LOG(LogTemp, Display, TEXT("Shoot. Ammo: %d/%d"), CurrentAmmo, MaxAmmo); // Docelowo tutaj wywo�anie UI aktualizuj�ce stan ammo } @@ -60,7 +62,7 @@ void UShootingComponent::Shoot() // Odrzut float RecoilPitch = FMath::RandRange(-1.0f, -0.5f); float RecoilYaw = FMath::RandRange(-0.5f, 0.5f); - + PlayerCharacter->AddControllerPitchInput(RecoilPitch * RecoilForceMultiplier); PlayerCharacter->AddControllerYawInput(RecoilYaw * RecoilForceMultiplier); @@ -69,6 +71,33 @@ void UShootingComponent::Shoot() DrawDebugLine(GetWorld(), LineStart, LineEnd, FColor::Red, false, 1.0f, 0, 1.0f); } +void UShootingComponent::MeleAttack() +{ + + FVector ForwardVector = PlayerCharacter->GetActorForwardVector(); + FVector ViewLocation; + FRotator ViewRotation; + PlayerCharacter->GetController()->GetPlayerViewPoint(ViewLocation, ViewRotation); + + FVector EndVector = ViewLocation + ForwardVector * MeleRange; + + FHitResult Hit; + FCollisionQueryParams QueryParams; + QueryParams.AddIgnoredActor(PlayerCharacter); + + //DrawDebugLine(GetWorld(), ViewLocation, EndVector, FColor::Red, false, 1.0f, 0, 1.0f); + + if (GetWorld()->LineTraceSingleByChannel(Hit, ViewLocation, EndVector, ECC_Visibility, QueryParams)) + { + if (Hit.GetActor()->Implements()) + { + IDamageable::Execute_TakeDamage(Hit.GetActor(), MeleDamageValue); + } + } + + +} + void UShootingComponent::Reload() { if (!bIsHoldingGun || bIsReloading) return; @@ -91,7 +120,7 @@ void UShootingComponent::PickUpGun(AGunBase* gunItem) HoldingGunClass = gunItem->GetClass(); MaxRange = gunItem->MaxRange; - DamageValue = gunItem->DamageValue; + FireDamageValue = gunItem->DamageValue; FireRateCooldown = gunItem->FireRateCooldown; RecoilForceMultiplier = gunItem->RecoilForceMultiplier; ReloadTime = gunItem->ReloadTime; @@ -115,7 +144,7 @@ void UShootingComponent::DropGun() if (DroppedGun) { DroppedGun->MaxRange = MaxRange; - DroppedGun->DamageValue = DamageValue; + DroppedGun->DamageValue = FireDamageValue; DroppedGun->FireRateCooldown = FireRateCooldown; DroppedGun->RecoilForceMultiplier = RecoilForceMultiplier; DroppedGun->ReloadTime = ReloadTime; diff --git a/Source/Exo/Private/Player/ExoPlayerController.cpp b/Source/Exo/Private/Player/ExoPlayerController.cpp index 1f783ba..61e52a1 100644 --- a/Source/Exo/Private/Player/ExoPlayerController.cpp +++ b/Source/Exo/Private/Player/ExoPlayerController.cpp @@ -38,6 +38,7 @@ void AExoPlayerController::BeginPlay() void AExoPlayerController::PlayerTick(float DeltaTime) { Super::PlayerTick(DeltaTime); + } void AExoPlayerController::SetupInputComponent() @@ -163,7 +164,7 @@ void AExoPlayerController::PlayerAim() void AExoPlayerController::PlayerMeleAttack() { - + ShootingComponent->MeleAttack(); } void AExoPlayerController::PlayerChangeWeapon() diff --git a/Source/Exo/Public/Characters/Components/ShootingComponent.h b/Source/Exo/Public/Characters/Components/ShootingComponent.h index 2912092..9db67e8 100644 --- a/Source/Exo/Public/Characters/Components/ShootingComponent.h +++ b/Source/Exo/Public/Characters/Components/ShootingComponent.h @@ -32,10 +32,13 @@ protected: public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - + UFUNCTION(Category = "Shooting") void Shoot(); + UFUNCTION(Category = "Mele Attack") + void MeleAttack(); + UFUNCTION(Category = "Shooting") void Reload(); @@ -48,6 +51,9 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting") float DropGunRange = 20.0f; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Mele Attack") + float MeleRange = 75.f; + private: void ResetFireCooldown(); @@ -64,7 +70,8 @@ private: bool bIsReloading = false; float MaxRange = 2000.0f; - float DamageValue = 100.0f; + float FireDamageValue = 100.0f; + float MeleDamageValue = 50.f; float FireRateCooldown = 1.0f; float RecoilForceMultiplier = 1.0f; float ReloadTime = 3.0f;