Merge branch 'WeaponSystem' into BackupBuild

# Conflicts:
#	EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset
#	EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp
This commit is contained in:
Rafal Swierczek 2023-10-16 11:23:56 +01:00
commit 07b6f9aeac
11 changed files with 81 additions and 39 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:30855616c4941635f2b4e9f78ebe1f4d7b43f219e4ae180257f666326433e4c6 oid sha256:dd6b7d124efa1086acb80f4b16e1d8a0db25e05e081f914d61cfce0bbb4191e9
size 42742 size 42329

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:652402df45503ab3169e329879f397101d9b5bf17551404301cca7b5b292eb68
size 62076

Binary file not shown.

View File

@ -24,6 +24,9 @@ void ABaseWeaponClass::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
collisionParams.AddIgnoredActor(playerInWorld);
collisionParams.AddIgnoredActor(this);
// Attempt to find the player character // Attempt to find the player character
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0); APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0);
playerInWorld = Cast<AEndlessVendettaCharacter>(PlayerController->GetCharacter()); playerInWorld = Cast<AEndlessVendettaCharacter>(PlayerController->GetCharacter());
@ -60,6 +63,13 @@ void ABaseWeaponClass::Tick(float DeltaTime)
{ {
ApplyRecoil(DeltaTime); ApplyRecoil(DeltaTime);
} }
UE_LOG(LogTemp, Display, TEXT("currnt pitch: %f"), currentPitch);
if (currentPitch < 0 && bStopShooting)
{
float increment = currentPitch * DeltaTime * 8;
currentPitch -= increment;
playerInWorld->AddControllerPitchInput(-increment);
}
} }
@ -73,6 +83,10 @@ void ABaseWeaponClass::GenerateRecoilVector()
recoilResultYaw = FMath::Sin(FMath::DegreesToRadians(angle)); recoilResultYaw = FMath::Sin(FMath::DegreesToRadians(angle));
recoilResultPitch = FMath::Cos(FMath::DegreesToRadians(angle)); recoilResultPitch = FMath::Cos(FMath::DegreesToRadians(angle));
if (bulletCountShoot >= howMnyShotsTillRclStop)
{
recoilResultPitch = 0;
}
//scaling direction to magnitude //scaling direction to magnitude
recoilResultPitch *= -tempMag; recoilResultPitch *= -tempMag;
recoilResultYaw *= tempMag; recoilResultYaw *= tempMag;
@ -87,11 +101,13 @@ void ABaseWeaponClass::ApplyRecoil(float DeltaTime)
{ {
float amplitude = RecoilCurve->GetFloatValue(recoilTime); //get current value of curve in time float amplitude = RecoilCurve->GetFloatValue(recoilTime); //get current value of curve in time
recoilTime += DeltaTime; recoilTime += DeltaTime;
if (bulletCountShoot <= 3) playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime)); if (bulletCountShoot <= 3)
traceEnd = traceStart + (UKismetMathLibrary::GetForwardVector(playerInWorld->GetControlRotation() * GetRecoilPitch(amplitude, recoilTime))); {
//UE_LOG(LogTemp, Warning, TEXT("Controller pitch: Pitch: %f Yaw: %f, Roll: %f"), playerInWorld->GetControlRotation().Pitch, playerInWorld->GetControlRotation().Yaw, playerInWorld->GetControlRotation().Roll); playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime));
currentPitch += GetRecoilPitch(amplitude,recoilTime);
}
GunStartArrow->AddRelativeRotation(FRotator(-GetRecoilPitch(amplitude, recoilTime), 0, 0));
playerInWorld->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime)); playerInWorld->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime));
//UE_LOG(LogTemp, Warning, TEXT("recoilTime: %f"), recoilTime);
UpdateSamples(amplitude, recoilTime); UpdateSamples(amplitude, recoilTime);
} }
} }
@ -139,8 +155,13 @@ void ABaseWeaponClass::ClickDetectionTimer()
void ABaseWeaponClass::CancelFire() void ABaseWeaponClass::CancelFire()
{ {
GetWorldTimerManager().ClearTimer(timerHandle); GetWorldTimerManager().ClearTimer(timerHandle);
if (bulletCountShoot <= 0) return;
UE_LOG(LogTemp, Display, TEXT("FireCancelled")); UE_LOG(LogTemp, Display, TEXT("FireCancelled"));
bulletCountShoot = 0; bulletCountShoot = 0;
GunStartArrow->SetRelativeRotation(FRotator(0));
//playerInWorld->GetController()->SetControlRotation(FRotator(0, playerInWorld->GetActorRotation().Yaw, playerInWorld->GetActorRotation().Roll));
bStopShooting = true;
nullSamples();
} }
void ABaseWeaponClass::Fire() void ABaseWeaponClass::Fire()
@ -150,26 +171,17 @@ void ABaseWeaponClass::Fire()
//do damage fallof based off distance //do damage fallof based off distance
traceStart = GunStartArrow->GetComponentLocation(); traceStart = GunStartArrow->GetComponentLocation();
traceEnd = traceStart + (GunStartArrow->GetForwardVector() * BulletDistance); traceEnd = traceStart + (GunStartArrow->GetForwardVector() * BulletDistance);
FCollisionQueryParams collisionParams; if (GetWorldTimerManager().IsTimerActive(timerHandle)) return;
collisionParams.AddIgnoredActor(playerInWorld);
collisionParams.AddIgnoredActor(this);
/*RecoilVerticalLimit(outHit);*/
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 DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, false, 5.0f, 0U, 1.5f);
DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, false, 0.2f, 0U, 1);
playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1); playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1);
currentAmmoCount -= 1; currentAmmoCount -= 1;
UE_LOG(LogTemp, Display, TEXT("Ammo Count: %d"), currentAmmoCount);
GenerateRecoilVector(); GenerateRecoilVector();
ClickDetectionTimer(); ClickDetectionTimer();
bulletCountShoot += 1; bulletCountShoot += 1;
bStopShooting = false;
if (outHit.bBlockingHit) if (outHit.bBlockingHit)
{ {
UE_LOG(LogTemp, Display, TEXT("Ammo Count: %s"), *outHit.GetActor()->GetName());
if (!Cast<AAICharacter>(outHit.GetActor())) return; if (!Cast<AAICharacter>(outHit.GetActor())) return;
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(WeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this); Cast<AAICharacter>(outHit.GetActor())->TakeDamage(WeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
} }
@ -185,10 +197,10 @@ void ABaseWeaponClass::WeaponScopedFire()
{ {
if (endlessVendettaChar->bIsScoped) if (endlessVendettaChar->bIsScoped)
{ {
recoilMagnitude -= 0.2f; recoilMagnitude = scopedRecoilMag;
recoilMaxAngleLeft /= 2.f; recoilMaxAngleLeft = scopedMaxAngleLeft;
recoilMaxAngleRight /= 2.f; recoilMaxAngleRight = scopedMaxAngleRight;
recoilMinMultiplier -= 0.2f; recoilMinMultiplier = scopedMinMultiplier;
} }
else else

View File

@ -24,10 +24,10 @@ protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
void GenerateRecoilVector();
void ApplyRecoil(float DeltaTime); void ApplyRecoil(float DeltaTime);
void GenerateRecoilVector();
void nullSamples(); void nullSamples();
//recoil previous curve //recoil previous curve
@ -54,12 +54,31 @@ public:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float FireRate; float FireRate;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere, BlueprintReadWrite)
int MagazineSize; int MagazineSize;
//how many bullets until the recoil stops going up
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
int howMnyShotsTillRclStop;
UPROPERTY(BlueprintReadWrite)
int currentAmmoCount;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UTexture2D* WeaponImage; UTexture2D* WeaponImage;
UPROPERTY(EditAnywhere, Category = "ScopedFire")
float scopedRecoilMag;
UPROPERTY(EditAnywhere, Category = "ScopedFire")
float scopedMaxAngleLeft;
UPROPERTY(EditAnywhere, Category = "ScopedFire")
float scopedMaxAngleRight;
UPROPERTY(EditAnywhere, Category = "ScopedFire")
float scopedMinMultiplier;
UFUNCTION(BlueprintCallable, Category = "Weapons") UFUNCTION(BlueprintCallable, Category = "Weapons")
virtual void Fire(); virtual void Fire();
@ -116,6 +135,8 @@ public:
FHitResult outHit; FHitResult outHit;
FVector traceStart; FVector traceStart;
FVector traceEnd; FVector traceEnd;
FVector newTraceEnd;
FCollisionQueryParams collisionParams;
//UFUNCTION(BlueprintCallable, Category = "Weapons") //UFUNCTION(BlueprintCallable, Category = "Weapons")
//void RecoilVerticalLimit(FHitResult Outhit); //void RecoilVerticalLimit(FHitResult Outhit);
@ -135,6 +156,6 @@ private:
float originalMaxAngleRight; float originalMaxAngleRight;
float originalMinMultiplier; float originalMinMultiplier;
int currentAmmoCount; float currentPitch;
bool bStopShooting = false;
}; };