Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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;

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

Product Version: Not Selected
more ▼

asked Apr 15 '14 at 05:54 AM in C++ Programming

avatar image

400 48 53 251

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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);

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

answered Apr 15 '14 at 11:53 AM

avatar image

BrɑκеPɑd STAFF
1.4k 33 22 78

avatar image Clunk47 Apr 16 '14 at 02:38 AM

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.

avatar image BrɑκеPɑd STAFF Apr 16 '14 at 09:16 AM

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:


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
     /** 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();

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question