How can I get the players camera velocity?

Hi Peeps so ive been trying to do this for a while now - I want to get to the players active camera and then grab its velocity for use.

Most recent attempt is by using "GetPlayerController(GetWorld(), 0)->GetPlayerCameraMAnager();

In the PlayerController.h PlayerCameraManager clearly exists but for some reason im getting the error : ‘GetPlayerCameraManager’: is not a member of ‘APlayerController’

Any ideas? Many thanks

I created a new class derived from Character called MyCharacter. In AMyCharacter::BeginPlay() I do the following:

void AMyCharacter::BeginPlay()
{
	Super::BeginPlay();
	const APlayerController* PC = UGameplayStatics::GetPlayerController(GetWorld(), 0);
	APlayerCameraManager* CameraManager = PC->PlayerCameraManager;
	UE_LOG(LogTemp, Warning, TEXT("%s"), *CameraManager->GetName());
	
}

When spawning, I get the following in my output log window:

I think the issue is that there is no explicit function called GetPlayerCameraManager() in PlayerController.h:

It is just a property you can access:

I hope this helps, and good luck :slight_smile:

Oh i see, hmm well that is interesting!

Also odd, theres a “GetPlayerCameraManager” function in BP! hehe

Humble Bump - Can anyone think of another way to basically do the same thing? :slight_smile:

For anyone else looking into this i was able to solve the problem with some help from the Unreal Discord.

The way i solved was by using this code:

PlayerCameraManager = PlayerController->PlayerCameraManager;

and then

CameraVelocity = PlayerCameraManager->GetVelocity();

hope this is helpful to someone :slight_smile:

Now i just need to figure out why “GetVelocity();” is returning 0 ?

hah!

The camera manager, at least I think, does not actually move or have a velocity, I believe you need the camera actor itself. This is only a guess, but the following function inside of APlayerController returns ACameraActor reference:

virtual ACameraActor* GetAutoActivateCameraForPlayer() const

Maybe this is a good starting place?

Hey DevinSherry thanks for the help, So I have used GetActorLocation(); on the camera manager to see if it moves or not and it does indeed move around when the player does.

Im wondering if this has to do with physics simulaton or not? i wonder if you know how to check / activate that to enable the GetVelocity(); function to work?

Many thanks! :slight_smile:

Ok did some digging and yes this is what it seems to be - I added a SceneComponent to the CameraManager and then checked / set that it was to simulate Physics.

After that i was able to use “GetComponentVelocity” :slight_smile:

not sure how to enable physics on a rootcomponent or if its possible without a scene component

EDIT:

Sorry this was wrong information the component i added was a USphereComponent and then SetSimpulatePhysics to True

:slight_smile:

1 Like