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
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
oid sha256:cff6a88ce5641de43b7168dbe156dc6c743108fd4fe22dd89647224cdc5249fc
size 37804
oid sha256:4473a9d8bdd893373d3b489bc1ccb878bc568d94b9b495b1e2be83880bac0959
size 37793

Binary file not shown.

View File

@ -141,6 +141,7 @@ void AEndlessVendettaCharacter::EquipPrimary()
if (IsValid(PrimaryWeapon))
{
PrimaryWeapon->Destroy();
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
PrimaryWeapon = nullptr;
bHasRifle = false;
return;
@ -171,6 +172,7 @@ void AEndlessVendettaCharacter::EquipSecondary()
if (IsValid(SecondaryWeapon))
{
SecondaryWeapon->Destroy();
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
SecondaryWeapon = nullptr;
bHasRifle = false;
return;
@ -208,7 +210,7 @@ void AEndlessVendettaCharacter::FireCaller()
void AEndlessVendettaCharacter::GunRightClick()
{
if (IsValid(PrimaryWeapon))
if (IsValid(PrimaryWeapon) && !bIsScoped)
{
for (UActorComponent* actorComp : this->GetComponentsByTag(UArrowComponent::StaticClass(), FName("ScopedLocationArrow")))
{
@ -217,11 +219,19 @@ void AEndlessVendettaCharacter::GunRightClick()
}
if (!IsValid(ScopedLocationArrow)) return;
PrimaryWeapon->SetActorLocation(ScopedLocationArrow->GetComponentLocation());
bIsScoped = true;
PrimaryWeapon->WeaponScopedFire();
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->SetActorLocation(ScopedLocationArrow->GetComponentLocation());
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))
{
bIsScoped = false;
PrimaryWeapon->WeaponScopedFire();
PrimaryWeapon->SetActorRelativeLocation(FVector(0,0,0));
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
}
if (IsValid(SecondaryWeapon))
{
bIsScoped = false;
SecondaryWeapon->WeaponScopedFire();
SecondaryWeapon->SetActorRelativeLocation(FVector(0,0,0));
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
}

View File

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

View File

@ -25,9 +25,11 @@ void ABaseWeaponClass::BeginPlay()
// Attempt to find the player character
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);
break;
@ -38,6 +40,10 @@ void ABaseWeaponClass::BeginPlay()
playerControllerRef = UGameplayStatics::GetPlayerController(GetWorld(), 0);
}
originalMagnitude = recoilMagnitude;
originalMaxAngleLeft = recoilMaxAngleLeft;
originalMaxAngleRight = recoilMaxAngleRight;
originalMinMultiplier = recoilMinMultiplier;
}
// Called every frame
@ -45,7 +51,7 @@ void ABaseWeaponClass::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (player)
if (playerInWorld)
{
ApplyRecoil(DeltaTime);
}
@ -76,8 +82,8 @@ void ABaseWeaponClass::ApplyRecoil(float DeltaTime)
{
float amplitude = RecoilCurve->GetFloatValue(recoilTime); //get current value of curve in time
recoilTime += DeltaTime;
player->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime));
player->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime));
playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime));
playerInWorld->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime));
UpdateSamples(amplitude, recoilTime);
}
}
@ -135,7 +141,7 @@ void ABaseWeaponClass::Fire()
traceStart = GunStartArrow->GetComponentLocation();
traceEnd = traceStart + (GunStartArrow->GetForwardVector() * BulletDistance);
FCollisionQueryParams collisionParams;
collisionParams.AddIgnoredActor(player);
collisionParams.AddIgnoredActor(playerInWorld);
collisionParams.AddIgnoredActor(this);
if (GetWorldTimerManager().IsTimerActive(timerHandle))
{
@ -155,11 +161,21 @@ void ABaseWeaponClass::Fire()
void ABaseWeaponClass::WeaponScopedFire()
{
UE_LOG(LogTemp, Display, TEXT("Activated WeaponScopedFire function in BaseWeaponClass"));
if (endlessVendettaChar->bIsScoped)
{
recoilMagnitude -= 0.2f;
recoilMaxAngleLeft /= 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();
UPROPERTY(VisibleAnywhere)
ACharacter* player;
ACharacter* playerInWorld;
AEndlessVendettaCharacter* endlessVendettaChar;
UPROPERTY()
APlayerController* playerControllerRef;
FTimerHandle timerHandle;
@ -116,4 +117,9 @@ private:
UPROPERTY(EditAnywhere)
float BulletDistance;
float originalMagnitude;
float originalMaxAngleLeft;
float originalMaxAngleRight;
float originalMinMultiplier;
};