Added Aim In Functionality for weapons

This commit is contained in:
Marcel Hara 2023-10-06 17:21:17 +01:00
parent 2c29972810
commit 13a3900e6d
8 changed files with 63 additions and 21 deletions

View File

@ -87,3 +87,6 @@ ConnectionType=USBOnly
bUseManualIPAddress=False bUseManualIPAddress=False
ManualIPAddress= ManualIPAddress=
[CoreRedirects]
+PropertyRedirects=(OldName="/Script/EndlessVendetta.BaseWeaponClass.player",NewName="/Script/EndlessVendetta.BaseWeaponClass.playerInWorld")

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:cff6a88ce5641de43b7168dbe156dc6c743108fd4fe22dd89647224cdc5249fc oid sha256:4473a9d8bdd893373d3b489bc1ccb878bc568d94b9b495b1e2be83880bac0959
size 37804 size 37793

Binary file not shown.

View File

@ -141,6 +141,7 @@ void AEndlessVendettaCharacter::EquipPrimary()
if (IsValid(PrimaryWeapon)) if (IsValid(PrimaryWeapon))
{ {
PrimaryWeapon->Destroy(); PrimaryWeapon->Destroy();
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
PrimaryWeapon = nullptr; PrimaryWeapon = nullptr;
bHasRifle = false; bHasRifle = false;
return; return;
@ -171,6 +172,7 @@ void AEndlessVendettaCharacter::EquipSecondary()
if (IsValid(SecondaryWeapon)) if (IsValid(SecondaryWeapon))
{ {
SecondaryWeapon->Destroy(); SecondaryWeapon->Destroy();
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
SecondaryWeapon = nullptr; SecondaryWeapon = nullptr;
bHasRifle = false; bHasRifle = false;
return; return;
@ -208,7 +210,7 @@ void AEndlessVendettaCharacter::FireCaller()
void AEndlessVendettaCharacter::GunRightClick() void AEndlessVendettaCharacter::GunRightClick()
{ {
if (IsValid(PrimaryWeapon)) if (IsValid(PrimaryWeapon) && !bIsScoped)
{ {
for (UActorComponent* actorComp : this->GetComponentsByTag(UArrowComponent::StaticClass(), FName("ScopedLocationArrow"))) for (UActorComponent* actorComp : this->GetComponentsByTag(UArrowComponent::StaticClass(), FName("ScopedLocationArrow")))
{ {
@ -217,11 +219,19 @@ void AEndlessVendettaCharacter::GunRightClick()
} }
if (!IsValid(ScopedLocationArrow)) return; if (!IsValid(ScopedLocationArrow)) return;
PrimaryWeapon->SetActorLocation(ScopedLocationArrow->GetComponentLocation()); PrimaryWeapon->SetActorLocation(ScopedLocationArrow->GetComponentLocation());
bIsScoped = true;
PrimaryWeapon->WeaponScopedFire(); PrimaryWeapon->WeaponScopedFire();
this->GetFirstPersonCameraComponent()->SetFieldOfView(50); //change this number to a number you can change in editor eventually this->GetFirstPersonCameraComponent()->SetFieldOfView(50); //change this number to a number you can change in editor eventually
} }
if (IsValid(SecondaryWeapon)) if (IsValid(SecondaryWeapon) && !bIsScoped)
{ {
for (UActorComponent* actorComp : this->GetComponentsByTag(UArrowComponent::StaticClass(), FName("ScopedLocationArrow")))
{
ScopedLocationArrow = Cast<UArrowComponent>(actorComp);
break;
}
if (!IsValid(ScopedLocationArrow)) return;
bIsScoped = true;
SecondaryWeapon->WeaponScopedFire(); SecondaryWeapon->WeaponScopedFire();
SecondaryWeapon->SetActorLocation(ScopedLocationArrow->GetComponentLocation()); SecondaryWeapon->SetActorLocation(ScopedLocationArrow->GetComponentLocation());
this->GetFirstPersonCameraComponent()->SetFieldOfView(50); //change this number to a number you can change in editor eventually this->GetFirstPersonCameraComponent()->SetFieldOfView(50); //change this number to a number you can change in editor eventually
@ -232,11 +242,15 @@ void AEndlessVendettaCharacter::StopGunRightClick()
{ {
if (IsValid(PrimaryWeapon)) if (IsValid(PrimaryWeapon))
{ {
bIsScoped = false;
PrimaryWeapon->WeaponScopedFire();
PrimaryWeapon->SetActorRelativeLocation(FVector(0,0,0)); PrimaryWeapon->SetActorRelativeLocation(FVector(0,0,0));
this->GetFirstPersonCameraComponent()->SetFieldOfView(90); this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
} }
if (IsValid(SecondaryWeapon)) if (IsValid(SecondaryWeapon))
{ {
bIsScoped = false;
SecondaryWeapon->WeaponScopedFire();
SecondaryWeapon->SetActorRelativeLocation(FVector(0,0,0)); SecondaryWeapon->SetActorRelativeLocation(FVector(0,0,0));
this->GetFirstPersonCameraComponent()->SetFieldOfView(90); this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
} }

View File

@ -111,6 +111,9 @@ public:
UArrowComponent* ScopedLocationArrow; UArrowComponent* ScopedLocationArrow;
UPROPERTY(EditAnywhere, Category = "Dont Touch")
bool bIsScoped;
protected: protected:
/** Called for movement input */ /** Called for movement input */
void Move(const FInputActionValue& Value); void Move(const FInputActionValue& Value);

View File

@ -25,9 +25,11 @@ void ABaseWeaponClass::BeginPlay()
// Attempt to find the player character // Attempt to find the player character
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0); APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0);
player = Cast<AEndlessVendettaCharacter>(PlayerController->GetCharacter()); playerInWorld = Cast<AEndlessVendettaCharacter>(PlayerController->GetCharacter());
for (UActorComponent* actorComp : player->GetComponentsByTag(UArrowComponent::StaticClass(), FName("GunStart"))) endlessVendettaChar = Cast<AEndlessVendettaCharacter>(playerInWorld);
for (UActorComponent* actorComp : playerInWorld->GetComponentsByTag(UArrowComponent::StaticClass(), FName("GunStart")))
{ {
GunStartArrow = Cast<UArrowComponent>(actorComp); GunStartArrow = Cast<UArrowComponent>(actorComp);
break; break;
@ -38,6 +40,10 @@ void ABaseWeaponClass::BeginPlay()
playerControllerRef = UGameplayStatics::GetPlayerController(GetWorld(), 0); playerControllerRef = UGameplayStatics::GetPlayerController(GetWorld(), 0);
} }
originalMagnitude = recoilMagnitude;
originalMaxAngleLeft = recoilMaxAngleLeft;
originalMaxAngleRight = recoilMaxAngleRight;
originalMinMultiplier = recoilMinMultiplier;
} }
// Called every frame // Called every frame
@ -45,7 +51,7 @@ void ABaseWeaponClass::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
if (player) if (playerInWorld)
{ {
ApplyRecoil(DeltaTime); ApplyRecoil(DeltaTime);
} }
@ -76,8 +82,8 @@ 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;
player->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime)); playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime));
player->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime)); playerInWorld->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime));
UpdateSamples(amplitude, recoilTime); UpdateSamples(amplitude, recoilTime);
} }
} }
@ -135,7 +141,7 @@ void ABaseWeaponClass::Fire()
traceStart = GunStartArrow->GetComponentLocation(); traceStart = GunStartArrow->GetComponentLocation();
traceEnd = traceStart + (GunStartArrow->GetForwardVector() * BulletDistance); traceEnd = traceStart + (GunStartArrow->GetForwardVector() * BulletDistance);
FCollisionQueryParams collisionParams; FCollisionQueryParams collisionParams;
collisionParams.AddIgnoredActor(player); collisionParams.AddIgnoredActor(playerInWorld);
collisionParams.AddIgnoredActor(this); collisionParams.AddIgnoredActor(this);
if (GetWorldTimerManager().IsTimerActive(timerHandle)) if (GetWorldTimerManager().IsTimerActive(timerHandle))
{ {
@ -155,11 +161,21 @@ void ABaseWeaponClass::Fire()
void ABaseWeaponClass::WeaponScopedFire() void ABaseWeaponClass::WeaponScopedFire()
{ {
UE_LOG(LogTemp, Display, TEXT("Activated WeaponScopedFire function in BaseWeaponClass")); if (endlessVendettaChar->bIsScoped)
{
recoilMagnitude -= 0.2f; recoilMagnitude -= 0.2f;
recoilMaxAngleLeft /= 2.f; recoilMaxAngleLeft /= 2.f;
recoilMaxAngleRight /= 2.f; recoilMaxAngleRight /= 2.f;
recoilMinMultiplier -= 2.f; recoilMinMultiplier -= 0.2f;
}
else
{
recoilMagnitude = originalMagnitude;
recoilMaxAngleLeft = originalMaxAngleLeft;
recoilMaxAngleRight = originalMaxAngleRight;
recoilMinMultiplier = originalMinMultiplier;
}
} }

View File

@ -69,9 +69,10 @@ public:
void CancelFire(); void CancelFire();
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
ACharacter* player; ACharacter* playerInWorld;
AEndlessVendettaCharacter* endlessVendettaChar;
UPROPERTY()
APlayerController* playerControllerRef; APlayerController* playerControllerRef;
FTimerHandle timerHandle; FTimerHandle timerHandle;
@ -116,4 +117,9 @@ private:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float BulletDistance; float BulletDistance;
float originalMagnitude;
float originalMaxAngleLeft;
float originalMaxAngleRight;
float originalMinMultiplier;
}; };