I am having trouble calculating the correct vector for my shoot mechanic. Here I initialize all the variables I will need to calculate the final vector. The problem is GetAdjustedAim always returns a Zero’ed out Vector.
void AArenaRangedWeapon_Instant::FireWeapon()
{
(...)
const FVector AimDir = GetAdjustedAim();
const FVector StartTrace = GetCameraDamageStartLocation(AimDir);
const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, ConeHalfAngle, ConeHalfAngle);
const FVector EndTrace = StartTrace + ShootDir * InstantConfig.WeaponRange;
(...)
}
Here is where I calculate the GetAdjustedAim. I get the PlayerController for the player and get the camLoc and the camRot. I zero out the vector so my result each iteration of FireWeapon() will be clean. However both the IF and the ELSE IF statement are always false. There must be something I don’t understand about the controller class.
FVector AArenaRangedWeapon::GetAdjustedAim() const
{
AArenaPlayerController* PlayerController = Instigator ? Cast<AArenaPlayerController>(Instigator->Controller) : NULL;
FVector FinalAim = FVector::ZeroVector;
// If we have a player controller use it for the aim
if (PlayerController)
{
FVector CamLoc;
FRotator CamRot;
PlayerController->GetPlayerViewPoint(CamLoc, CamRot);
FinalAim = CamRot.Vector();
}
else if (Instigator)
{
// Now see if we have an AI controller - we will want to get the aim from there if we do
AArenaAIController* AIController = MyPawn ? Cast<AArenaAIController>(MyPawn->Controller) : NULL;
if (AIController != NULL)
{
FinalAim = AIController->GetControlRotation().Vector();
}
else
{
FinalAim = Instigator->GetBaseAimRotation().Vector();
}
}
return FinalAim;
}
Here is where I initialize the Instigator and the MyPawn so that they are valid.
void AArenaRangedWeapon::SetOwningPawn(ATheArenaCharacter* NewOwner)
{
if (MyPawn != NewOwner)
{
Instigator = NewOwner;
MyPawn = NewOwner;
// net owner for RPC calls
SetOwner(NewOwner);
}
}
If anyone could take a look at this and give me some ideas as to what is going on they would be a real champion!