Unreal/Game 2

8.3 Screen Center Aim Shooting

kyoun 2019. 6. 25. 16:49

카메라에서 스크린 중앙 방향으로 발사



1.  Camera Componet 이용한 방법  

	auto Location = m_Camera->GetComponentLocation();
	auto Rot = m_Camera->GetComponentRotation();



	DrawDebugLine(GetWorld(), 
		Location,
		Location + (Rot.Vector() * AttackLength), 
                FColor::Red, false, 2, 0, 2);

 



2. APlayerCameraManager 이용한 방법 

APlayerCameraManager *camManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;

FVector camLocation = camManager->GetCameraLocation();
FVector camForward = camManager->GetCameraRotation().Vector();

	
DrawDebugLine(World,
    camLocation,
    camLocation + (camForward * AttackLength), FColor::Red, false, 2, 0, 2);

 

 

 

3. 디버깅

 



4. OnHIt 이펙트 추가 


	FHitResult HitResult;
	FCollisionQueryParams Params(NAME_None, false, this);

	bool bResult = GetWorld()->LineTraceSingleByChannel(
		HitResult,
		m_Camera->GetComponentLocation(),
		m_Camera->GetComponentLocation() + (m_Camera->GetComponentRotation().Vector() * AttackLength),
		ECollisionChannel::ECC_Visibility);


	if (bResult == true)
	{
		UGameplayStatics::SpawnEmitterAtLocation(GetWorld(),
			CurrentWeapon->HitEffect,
			HitResult.ImpactPoint);
        }