Camera orbit around player?

I’ve been messing w/ PlayerCameraManager and successfully set my custom camera manager to my custom player controller, and all assigned to my custom game mode… All I can really do w/ the camera is change FOV and other editor exposed properties. I’d like to have the camera orbit my ship and keep looking at the ship, while moving the mouse. Mouse X will orbit yaw, Mouse Y to orbit Pitch. I’ve managed to get a mesh to kinda “orbit” a specific point by using RotateAngleAxis… I feel lost at this point, been searching for about 10 hours straight for an answer to what is probably super easy to do.

here’s some pseudo for what I’m trying to do

Target = ShipMesh;

if(MouseX)
    Camera.RotateAround(Target.UpVector);
if(MouseY)
    Camera.RotateAround(Target.RightVector);
Camera.LookAt(Target);

I’m trying to achieve this in C++ without using any blueprint assistance. Any help will be greatly appreciated.

Hi! Again, completely untested, but something like this might get you started:

float DeltaPitch, DeltaYaw;

const FVector CameraLocation = Camera->GetActorLocation();
const FVector TargetToCameraVector = CameraLocation - Target->GetActorLocation();

// Rotate the Camera around Target
const FRotationMatrix DeltaRotation(FRotator(DeltaPitch, DeltaYaw, 0.f));
const FVector NewLocation = CameraLocation + DeltaRotation.TransformLocation(TargetToCameraVector);
Camera->SetActorLocation(NewLocation);

// Make Camera look at Target
Camera->SetActorRotation((Target->GetActorLocation() - NewLocation).Rotator());

Hi, what type of class would I add this too? Camera is an unknown identifier when trying to implement this in PlayerCameraManager class. Also, how would I declare a target? Sorry but I am completely new and UE4 programming is way different than what I’m used to.

No problem! Sorry, I’d missed the fact you were using a PlayerCameraManager. I’m not overly-familiar with this code myself, but it might be worth reading through this article if you haven’t already:

https://docs.unrealengine.com/latest/INT/Programming/Gameplay/Framework/Camera/index.html

I think all you should do is override CalcCamera in your Pawn/Character class. You could the put the logic for your camera movement in there, and keep a hold of the view rotations as member variables in your pawn, updated by player input.

The CalcCamera function could look something like this:

class AMyPlayer : public APawn
{
public:
	/** Camera pitch and yaw rotations, updated by mouse axis in player input */
	float CameraPitch, CameraYaw;

	virtual void CalcCamera(float DeltaTime, struct FMinimalViewInfo& OutResult) OVERRIDE;
...
};

void AMyPlayer::CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult)
{

	// Put the camera 3 meters behind the pawn
	static const float CameraOffset = 300.f;

	const FVector CharacterLocation = GetActorLocation();
	const FRotationMatrix CameraRotation(FRotator(CameraPitch, CameraYaw, 0.f));

	// Assume the back of the player is -ve x axis
	const FVector PreTransformedCameraPos(-CameraOffset, 0, 0);
	const FVector CameraLocation = CharacterLocation + CameraRotation.TransformPosition(PreTransformedCameraPos);
	OutResult.Location = CameraLocation;

	// Make Camera look at Target
	OutResult.Rotation = (CharacterLocation - CameraLocation).Rotation();
}