Added working firerate to weapons & sorted out hold and tap fire

This commit is contained in:
MARCEL HARA 2023-10-02 14:47:49 +01:00
parent 2242379657
commit 93447bde97
11 changed files with 24 additions and 72 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:00e38eda0524fe228dc71f14ef9f96ebec3f8142ffaeca9366f253a7456d529b oid sha256:059c5de9ae43a57d471949157f8c1e59bcbc14c1ca117627ccb9d1b27036c180
size 27305 size 27098

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -88,9 +88,7 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
EnhancedInputComponent->BindAction(EquipSecondaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipSecondary); EnhancedInputComponent->BindAction(EquipSecondaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipSecondary);
//Weapon Shooting //Weapon Shooting
EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::TapFireCaller); EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::FireCaller);
EnhancedInputComponent->BindAction(HoldShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::HoldFireCaller);
//EnhancedInputComponent->BindAction(HoldShootAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::CancelFire);
} }
} }
@ -195,34 +193,19 @@ void AEndlessVendettaCharacter::EquipSecondary()
} }
//Calls the fire function in the baseWeaponClass //Calls the fire function in the baseWeaponClass
void AEndlessVendettaCharacter::TapFireCaller() void AEndlessVendettaCharacter::FireCaller()
{ {
UE_LOG(LogTemp, Warning, TEXT("Tap Fire")); UE_LOG(LogTemp, Warning, TEXT("Tap Fire"));
if (IsValid(PrimaryWeapon)) if (IsValid(PrimaryWeapon))
{ {
PrimaryWeapon->TapFire(); PrimaryWeapon->Fire();
} }
if (IsValid(SecondaryWeapon)) if (IsValid(SecondaryWeapon))
{ {
SecondaryWeapon->TapFire(); SecondaryWeapon->Fire();
} }
} }
void AEndlessVendettaCharacter::HoldFireCaller()
{
UE_LOG(LogTemp, Warning, TEXT("Hold Fire"));
if (IsValid(PrimaryWeapon) || IsValid(SecondaryWeapon))
{
PrimaryWeapon->HoldFire();
}
}
void AEndlessVendettaCharacter::CancelFire()
{
PrimaryWeapon->CancelFire();
}
void AEndlessVendettaCharacter::Move(const FInputActionValue& Value) void AEndlessVendettaCharacter::Move(const FInputActionValue& Value)
{ {

View File

@ -101,12 +101,8 @@ public:
ABaseWeaponClass* SecondaryWeapon; ABaseWeaponClass* SecondaryWeapon;
UFUNCTION(BlueprintCallable, Category = "Weapons") UFUNCTION(BlueprintCallable, Category = "Weapons")
void TapFireCaller(); void FireCaller();
UFUNCTION(BlueprintCallable, Category = "Weapons")
void HoldFireCaller();
void CancelFire();
protected: protected:
/** Called for movement input */ /** Called for movement input */

View File

@ -39,13 +39,7 @@ void ABaseWeaponClass::Tick(float DeltaTime)
void ABaseWeaponClass::ClickDetectionTimer() void ABaseWeaponClass::ClickDetectionTimer()
{ {
if (GetWorldTimerManager().IsTimerActive(timerHandle)) GetWorldTimerManager().SetTimer(timerHandle, this, &ABaseWeaponClass::Fire, 1 / FireRate, false);
{
return;
}
GetWorldTimerManager().SetTimer(timerHandle, this, &ABaseWeaponClass::TapFire, 1 / FireRate, false);
} }
void ABaseWeaponClass::CancelFire() void ABaseWeaponClass::CancelFire()
@ -53,7 +47,7 @@ void ABaseWeaponClass::CancelFire()
GetWorldTimerManager().ClearTimer(timerHandle); GetWorldTimerManager().ClearTimer(timerHandle);
} }
void ABaseWeaponClass::TapFire() void ABaseWeaponClass::Fire()
{ {
FHitResult outHit; FHitResult outHit;
FVector traceStart; FVector traceStart;
@ -63,32 +57,17 @@ void ABaseWeaponClass::TapFire()
FCollisionQueryParams collisionParams; FCollisionQueryParams collisionParams;
collisionParams.AddIgnoredActor(player); collisionParams.AddIgnoredActor(player);
collisionParams.AddIgnoredActor(this); collisionParams.AddIgnoredActor(this);
if (GetWorldTimerManager().IsTimerActive(timerHandle))
{
return;
}
GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams); GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams);
//Debug line to see where the trace hit //Debug line to see where the trace hit
DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, true, 500.0f, 0U, 5.f); DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, true, 500.0f, 0U, 5.f);
ClickDetectionTimer();
if (outHit.bBlockingHit) if (outHit.bBlockingHit)
{ {
UE_LOG(LogTemp, Display, TEXT("hit item: %s"), *outHit.GetActor()->GetName()); UE_LOG(LogTemp, Display, TEXT("hit item: %s"), *outHit.GetActor()->GetName());
} }
} }
void ABaseWeaponClass::HoldFire()
{
FHitResult outHit;
FVector traceStart;
FVector traceEnd;
traceStart = GunStartArrow->GetComponentLocation();
traceEnd = traceStart + (player->GetActorForwardVector() * BulletDistance);
FCollisionQueryParams collisionParams;
collisionParams.AddIgnoredActor(player);
collisionParams.AddIgnoredActor(this);
GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams);
//Debug line to see where the trace hit
DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, true, 500.0f, 0U, 5.f);
if (outHit.bBlockingHit)
{
UE_LOG(LogTemp, Display, TEXT("hit item: %s"), *outHit.GetActor()->GetName());
}
}

View File

@ -43,10 +43,7 @@ public:
UTexture2D* WeaponImage; UTexture2D* WeaponImage;
UFUNCTION(BlueprintCallable, Category = "Weapons") UFUNCTION(BlueprintCallable, Category = "Weapons")
void TapFire(); void Fire();
UFUNCTION(BlueprintCallable, Category = "Weapons")
void HoldFire();
UFUNCTION(BlueprintCallable, Category = "Weapons") UFUNCTION(BlueprintCallable, Category = "Weapons")
void ClickDetectionTimer(); void ClickDetectionTimer();