The-Cowboy
(The-Cowboy)
February 11, 2020, 11:02pm
1
I am writing an AI for an FPS game. To set aim, I am using
SetFocalPoint(Enemy->GetActorLocation())
in the AIController class. However it is not setting the correct pitch of the controller. When I use
SetFocus(Enemy)
it works fine. Am I missing something?
The-Cowboy
(The-Cowboy)
February 12, 2020, 10:08pm
2
I found the solution. The method UpdateControlRotation() in AIController ignores the pitch if the target is not pawn
void AAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn)
{
APawn* const MyPawn = GetPawn();
if (MyPawn)
{
FRotator NewControlRotation = GetControlRotation();
// Look toward focus
const FVector FocalPoint = GetFocalPoint();
if (FAISystem::IsValidLocation(FocalPoint))
{
NewControlRotation = (FocalPoint - MyPawn->GetPawnViewLocation()).Rotation();
}
else if (bSetControlRotationFromPawnOrientation)
{
NewControlRotation = MyPawn->GetActorRotation();
}
//** Don't pitch view unless looking at another pawn**
if (NewControlRotation.Pitch != 0 && Cast<APawn>(GetFocusActor()) == nullptr)
{
NewControlRotation.Pitch = 0.f;
}
SetControlRotation(NewControlRotation);
if (bUpdatePawn)
{
const FRotator CurrentPawnRotation = MyPawn->GetActorRotation();
if (CurrentPawnRotation.Equals(NewControlRotation, 1e-3f) == false)
{
MyPawn->FaceRotation(NewControlRotation, DeltaTime);
}
}
}
}
So if you want the pitch to be applied, simply override the method in the child class! Dunno why it ignores the pitch by default.
1 Like
sivan
(sivan)
February 15, 2020, 11:40pm
3
earlier I had a lot of problems with focal point and focus on an actor, as I remember you need to set nullptr to focus then you can use focal point properly…