APawn::GetViewRotation
#include "GameFramework/Pawn.h"
Access: public
Specifiers: virtualconst
Description
Returns the rotation representing where the pawn is looking, typically the controller's ControlRotation. Override this to provide a custom view direction, such as for a vehicle turret that rotates independently of the body.
Caveats & Gotchas
- • On simulated proxies (remote clients in multiplayer) the rotation returned is derived from the replicated RemoteViewPitch16 compressed value — only pitch is replicated, so yaw comes from the pawn's actor rotation.
- • If the pawn has no controller (e.g. after possession ends), the default implementation returns the pawn's actor rotation rather than a controller rotation.
Signature
virtual FRotator GetViewRotation() const Return Type
FRotator Example
Use view rotation to spawn a projectile facing the camera C++
FRotator ViewRot = GetViewRotation();
FVector SpawnLoc = GetPawnViewLocation() + ViewRot.Vector() * 100.f;
GetWorld()->SpawnActor<AMyProjectile>(ProjectileClass, SpawnLoc, ViewRot); Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?