Updated GunShooting to fix grabbing forward vector of guncomp
This commit is contained in:
		
							parent
							
								
									5743e885e0
								
							
						
					
					
						commit
						fed24de414
					
				@ -1,3 +1,3 @@
 | 
			
		||||
version https://git-lfs.github.com/spec/v1
 | 
			
		||||
oid sha256:d580d82ff6abdbebffa1e57dc264fb6e4b0e6c53e28aa0c853b56149f7867471
 | 
			
		||||
oid sha256:00e38eda0524fe228dc71f14ef9f96ebec3f8142ffaeca9366f253a7456d529b
 | 
			
		||||
size 27305
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,3 @@
 | 
			
		||||
version https://git-lfs.github.com/spec/v1
 | 
			
		||||
oid sha256:21afd371e599a3fb2c37e3662406978c3305c602a1c77bb3717e9bc4f2514b48
 | 
			
		||||
size 35926
 | 
			
		||||
oid sha256:6c3599c78d84a6895d06de8ce3697a6aefd517ac0105d041cab6f5124090bb3b
 | 
			
		||||
size 35834
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,3 @@
 | 
			
		||||
version https://git-lfs.github.com/spec/v1
 | 
			
		||||
oid sha256:51cc0f9f0adae065e9941acdd88abe2fe5f7015a3a5343a63f7b0507e90c21ed
 | 
			
		||||
size 28900
 | 
			
		||||
oid sha256:694f084a31b369305b9cf0e066786a624f73721bf819d3823177703341f0b98c
 | 
			
		||||
size 28902
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,3 @@
 | 
			
		||||
version https://git-lfs.github.com/spec/v1
 | 
			
		||||
oid sha256:5b8b34286278ebb69adb37de9d922ea859ecab2e2547f7e3a634d75c61522828
 | 
			
		||||
oid sha256:51fdff374c4c25c321646b9315bc5286b1ddc89511a597538bf96bea96222e02
 | 
			
		||||
size 5061
 | 
			
		||||
 | 
			
		||||
@ -89,7 +89,8 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
 | 
			
		||||
 | 
			
		||||
		//Weapon Shooting
 | 
			
		||||
		EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::TapFireCaller);
 | 
			
		||||
		EnhancedInputComponent->BindAction(HoldShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::TapFireCaller);
 | 
			
		||||
		EnhancedInputComponent->BindAction(HoldShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::HoldFireCaller);
 | 
			
		||||
		//EnhancedInputComponent->BindAction(HoldShootAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::CancelFire);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -197,10 +198,28 @@ void AEndlessVendettaCharacter::EquipSecondary()
 | 
			
		||||
void AEndlessVendettaCharacter::TapFireCaller()
 | 
			
		||||
{
 | 
			
		||||
	UE_LOG(LogTemp, Warning, TEXT("Tap Fire"));
 | 
			
		||||
	 if (IsValid(PrimaryWeapon) || IsValid(SecondaryWeapon))
 | 
			
		||||
	 if (IsValid(PrimaryWeapon))
 | 
			
		||||
	 {
 | 
			
		||||
	 	PrimaryWeapon->TapFire();
 | 
			
		||||
		 PrimaryWeapon->TapFire();
 | 
			
		||||
	 }
 | 
			
		||||
	 if (IsValid(SecondaryWeapon))
 | 
			
		||||
	 {
 | 
			
		||||
		 SecondaryWeapon->TapFire();
 | 
			
		||||
	 }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AEndlessVendettaCharacter::HoldFireCaller()
 | 
			
		||||
{
 | 
			
		||||
	UE_LOG(LogTemp, Warning, TEXT("Hold Fire"));
 | 
			
		||||
	if (IsValid(PrimaryWeapon) || IsValid(SecondaryWeapon))
 | 
			
		||||
	{
 | 
			
		||||
		PrimaryWeapon->HoldFire();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AEndlessVendettaCharacter::CancelFire()
 | 
			
		||||
{
 | 
			
		||||
	PrimaryWeapon->CancelFire();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -103,6 +103,11 @@ public:
 | 
			
		||||
	UFUNCTION(BlueprintCallable, Category = "Weapons")
 | 
			
		||||
	void TapFireCaller();
 | 
			
		||||
 | 
			
		||||
	UFUNCTION(BlueprintCallable, Category = "Weapons")
 | 
			
		||||
	void HoldFireCaller();
 | 
			
		||||
 | 
			
		||||
	void CancelFire();
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	/** Called for movement input */
 | 
			
		||||
	void Move(const FInputActionValue& Value);
 | 
			
		||||
 | 
			
		||||
@ -37,9 +37,44 @@ void ABaseWeaponClass::Tick(float DeltaTime)
 | 
			
		||||
	Super::Tick(DeltaTime);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ABaseWeaponClass::ClickDetectionTimer()
 | 
			
		||||
{
 | 
			
		||||
	if (GetWorldTimerManager().IsTimerActive(timerHandle))
 | 
			
		||||
	{
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	GetWorldTimerManager().SetTimer(timerHandle, this, &ABaseWeaponClass::TapFire, 1 / FireRate, false);
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ABaseWeaponClass::CancelFire()
 | 
			
		||||
{
 | 
			
		||||
	GetWorldTimerManager().ClearTimer(timerHandle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ABaseWeaponClass::TapFire()
 | 
			
		||||
{
 | 
			
		||||
	FTimerHandle timerHandle;
 | 
			
		||||
	FHitResult outHit;
 | 
			
		||||
	FVector traceStart;
 | 
			
		||||
	FVector traceEnd;
 | 
			
		||||
	traceStart = GunStartArrow->GetComponentLocation();
 | 
			
		||||
	traceEnd = traceStart + (GunStartArrow->GetForwardVector() * 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());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ABaseWeaponClass::HoldFire()
 | 
			
		||||
{
 | 
			
		||||
	FHitResult outHit;
 | 
			
		||||
	FVector traceStart;
 | 
			
		||||
	FVector traceEnd;
 | 
			
		||||
@ -48,7 +83,6 @@ void ABaseWeaponClass::TapFire()
 | 
			
		||||
	FCollisionQueryParams collisionParams;
 | 
			
		||||
	collisionParams.AddIgnoredActor(player);
 | 
			
		||||
	collisionParams.AddIgnoredActor(this);
 | 
			
		||||
	GetWorldTimerManager().SetTimer(timerHandle, 1 / FireRate, false, 1.0f);
 | 
			
		||||
	GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams);
 | 
			
		||||
 | 
			
		||||
	//Debug line to see where the trace hit
 | 
			
		||||
@ -56,6 +90,5 @@ void ABaseWeaponClass::TapFire()
 | 
			
		||||
	if (outHit.bBlockingHit)
 | 
			
		||||
	{
 | 
			
		||||
		UE_LOG(LogTemp, Display, TEXT("hit item: %s"), *outHit.GetActor()->GetName());
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -45,9 +45,21 @@ public:
 | 
			
		||||
	UFUNCTION(BlueprintCallable, Category = "Weapons")
 | 
			
		||||
	void TapFire();
 | 
			
		||||
 | 
			
		||||
	UFUNCTION(BlueprintCallable, Category = "Weapons")
 | 
			
		||||
	void HoldFire();
 | 
			
		||||
 | 
			
		||||
	UFUNCTION(BlueprintCallable, Category = "Weapons")
 | 
			
		||||
	void ClickDetectionTimer();
 | 
			
		||||
 | 
			
		||||
	void CancelFire();
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(VisibleAnywhere)
 | 
			
		||||
	ACharacter* player;
 | 
			
		||||
 | 
			
		||||
	FTimerHandle timerHandle;
 | 
			
		||||
 | 
			
		||||
	bool bFirstBulletShot = false;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
	UArrowComponent* GunStartArrow;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user