Tweaked AR Recoil Vals and Added Moving Error to all weapons

This commit is contained in:
MH261677 2023-10-10 12:58:45 +01:00
parent cd38898a58
commit 13d96ad67c
5 changed files with 34 additions and 20 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:3194a5d00e86f1294c85008ba95e40c7d09358e3df2d8360945f78a20dc0a78d oid sha256:d4914d01f2581bf5c3edc200811e9990ccc825755171a4fc83bfb0ef12bcb145
size 37917 size 38083

View File

@ -75,7 +75,11 @@ 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;
@ -92,9 +96,7 @@ void ABaseWeaponClass::ApplyRecoil(float DeltaTime)
recoilTime += DeltaTime; recoilTime += DeltaTime;
if (bulletCountShoot <= 3) playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime)); if (bulletCountShoot <= 3) playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime));
GunStartArrow->AddRelativeRotation(FRotator(-GetRecoilPitch(amplitude, recoilTime), 0, 0)); GunStartArrow->AddRelativeRotation(FRotator(-GetRecoilPitch(amplitude, recoilTime), 0, 0));
//traceEnd = GunStartArrow->GetComponentLocation() + (GunStartArrow->GetComponentRotation().Pitch * GetRecoilPitch(amplitude, recoilTime));
playerInWorld->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime)); playerInWorld->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime));
//UE_LOG(LogTemp, Warning, TEXT("recoilTime: %f"), recoilTime);
UpdateSamples(amplitude, recoilTime); UpdateSamples(amplitude, recoilTime);
} }
} }
@ -155,24 +157,20 @@ 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);
/*RecoilVerticalLimit(outHit);*/
if (GetWorldTimerManager().IsTimerActive(timerHandle)) return; if (GetWorldTimerManager().IsTimerActive(timerHandle)) return;
GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams); GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams);
DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, false, 5.0f, 0U, 2.5f); DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, false, 5.0f, 0U, 1.5f);
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;
if (bulletCountShoot <= 1) if (bulletCountShoot <= 1)
{ {
ogPlayerRotation = FRotator(playerControllerRef->GetControlRotation()); ogPlayerRotation = FRotator(playerControllerRef->GetControlRotation());
UE_LOG(LogTemp, Display, TEXT("FIRST BULLET FIRED: %s"), *ogPlayerRotation.ToString());
} }
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);
} }
@ -188,10 +186,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,9 +24,9 @@ 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();
@ -44,7 +44,7 @@ protected:
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
FName WeaponName; FName WeaponName;
@ -57,9 +57,25 @@ public:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
int MagazineSize; int MagazineSize;
//how many bullets until the recoil stops going up
UPROPERTY(EditAnywhere)
int howMnyShotsTillRclStop;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
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();