As was pointed out in this archived post, AIPerception uses GetActorViewPoint to determine the Sight Sense location and orientation. Unfortunately, this function cannot be overridden in blueprints yet. However, you can very easily override it in C++ and update the actor viewport with the location and rotation of “head” bone to achieve the effect you want. Hence, if you really need this, you have to do a little bit of coding. It’s not that difficult though. Here’s a quick step by step guide on how to accomplish this:
-
In the Content Browser, click on the green button Add New > New C++ Class. Select Character and name it BaseCharacter.
-
Th Engine will take a short moment to create this class and recompile the solution. If you’re on Windows and have Visual Studio installed, it will open automatically. Once the Visual Studio opens, go to the BaseCharacter.h and override GetActorViewpoint method as a public function by adding the following line within those curly brackets:
void GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const override;
-
Go to BaseCharacter.cpp and add these few lines:
void ABaseCharacter::GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const
{
Location = GetMesh()->GetSocketLocation(“head”);Rotation = GetActorRotation(); Rotation.Yaw -= GetMesh()->GetSocketTransform("head", RTS_ParentBoneSpace).Rotator().Roll;
}
This uses the default’s Third Person skeleton and the “head” bone to update these Location and Rotation values.
That’s it! Now go back to the Editor, and compile your solution. If you’re already in the blueprint version of ThirdPersonTemplate, then simply open the ThirdPersonCharacter blueprint, go to the Class Settings and on the top right, change the Parent Class to this BaseCharacter. If you’re building your own Character, then use this BaseCharacter as the parent and create a new blueprint from it (one simple way to do this is to find this C++ BaseCharacter class in the Content Browser, right-click on it and create a new blueprint class from it). Next, create an AIController, add the AIPerception to it, and enable Sight Sense. The Yaw angle of Sight Sense will automatically get updated as this Character turns his head.
Hope this helps.
~Vizgin