Currently I am trying to figure out which functions to use in order to set the camera attached to the gun as the viewport character’s camera. I successfully deactivated the follow camera now all that needs to be done is activate the child class of the gun itself which is the ADSCamera. Any help would be much appreciated, thank you!
void AWeaponBase::IsAiming()
{
ATheProjectNameCharacter* Player = Cast<ATheProjectNameCharacter>
(UGameplayStatics::GetPlayerCharacter(this, 0));
bisAiming = true;
bool IsNewActive = true;
if (bisAiming)
{
Player->FollowCamera->Deactivate();
ADSCamera->Activate();
ADSCamera->SetActive(IsNewActive);
}
}
void ATheProjectNameCharacter::AimDownSights()
{
//Calling the function.
if (CurrentWeapon)
{
CurrentWeapon->IsAiming();
}
}
It’s weird cause it is easy to just place the camera inside of the character then activate and deactivate both cameras. But when calling the camera from a separate actor it is tougher for whatever reason.
//I figure out how to aim but now I need to set the camera transform back to the old location. Any tips?
void AWeaponBase::IsAiming()
{
ACharacter* Player = Cast(UGameplayStatics::GetPlayerCharacter(this, 0));
bisAiming = true;
FViewTargetTransitionParams Params;
const FTransform SocketTransform = WeaponBaseMesh->GetSocketTransform(FName(“ADS_Socket”));
//const FRotator SocketRotation = WeaponBaseMesh->GetSocketRotation(FName(“ADS_Socket”));
I set the a socket on the firearm then I set the player character’s camera to the world transform socket of the firearm. I did not create another camera.
//I created a socket for the follow camera where the head of the character is, then I transferred the camera back and forth between both sockets. The one for the gun that I had created and the one for the character’s follow camera.
void AWeaponBase::IsAiming()
{
AProjectNameCharacter* Player = Cast(UGameplayStatics::GetPlayerCharacter(this, 0));
FViewTargetTransitionParams Params;
const FTransform SocketTransform = WeaponBaseMesh->GetSocketTransform(FName(“M4A1ADS_Socket”));
if (bisAiming)
{
Player->FollowCamera->SetWorldTransform(SocketTransform);
Player->FollowCamera->SetFieldOfView(60.0f);
bisAiming = false;
}
}
void AWeaponBase::IsNotAiming()
{
AProjectNameCharacter* Player = Cast(UGameplayStatics::GetPlayerCharacter(this, 0));
const FTransform SocketTransform2 = Player->GetMesh()->GetSocketTransform(FName(“HeadSocket”));
if (!bisAiming)
{
Player->FollowCamera->SetWorldTransform(SocketTransform2);
Player->FollowCamera->SetFieldOfView(80.0f);
bisAiming = true;
}
}