How can I locking the player camera to a target?

What I’m trying to achieve is making it so the players camera will stay focused on an Actor while the player presses a button.

For those that have used SetFocus within AI, this is exactly what I’m trying to do but for the player

Currently I have (and understand):

  • a trace to pick-up the players current target i.e. the actor they’re looking at
  • The ability to use player input, button presses

I know how I can set this up but not how to make the cameras’ rotation and the players rotation change based on an angle etc.

Any help would be great :smiley:

So after searching around for a while I’ve got this:

	FRotator Rotation = (Target->GetActorLocation() - GetActorLocation()).Rotation();
	FirstPersonCameraComponent->SetRelativeRotation(Rotation);
	SetActorRotation(Rotation);

This almost works perfectly, the player does move round their target in a circle but the rotation isn’t quite right. I’m always facing with the target to my left, any ideas?

Are you trying to change only the camera rotation or the character’s location as well?

All it has to do is make the player and the camera turn to face the target, the player can move normally but they can’t change their direction.

I’ve got it all set-up and working apart from the player and camera doesn’t face the target properly.

Hi Belven,

Have you tried using FindLookAtRotation in the KismetMathLibrary? That might be helpful in this instance.

Wow, great i’ll have a look :smiley: