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"

Orbit the camera around a vector

Hi everyone, I currently have a camera that I want to be able to rotate around a point when I swipe left or right in the touch screen and for that I already have a InputManager with the possible input methods bound.

I have a touchEvent and swipe event bound by the method

 BindTouch(IE_Pressed, this, &AMyplayerController::TouchEvent)
 BindTouch(IE_REPEAT, this, &AMyplayerController::SwipeEvent)

I want to be able to move the camera right or left depending on the swipe direction while being able to keep looking at FVector(0, 0, 0) which is the point of origin of the world.

The InputManager already has a reference to the camera that is on the screen, so is there anyway to make it rotate or obit around that point and keep looking at it even though it is moving?

Thank you.

Product Version: UE 4.10
more ▼

asked Jan 12 '16 at 01:27 PM in C++ Programming

avatar image

23 14 17 22

avatar image Matthew J Jan 12 '16 at 05:43 PM

Hi WolfAlvein

If you focus on applying the rotation to the Spring Arm rather than the Camera and have the location of the Spring Arm at (0, 0, 0) as well, it should rotate in the way you're looking for. If it does some odd stuff due to the Camera and/or Spring Arm being at an angle, be sure to do the rotation in World space instead of Local space. This will let it rotate along the usual X, Y, and Z axis rather than the relative one.

Hope this helps!

avatar image WolfAlvein Jan 12 '16 at 06:36 PM

Hi Matthew thanks for your answer I'll be sure to test it out, but I was thinking of something without the use of a Spring Arm just to test out how to do it.

Thank you again.

avatar image WolfAlvein Jan 15 '16 at 06:23 PM

Hi Matthew I decided to implement the movement of the camera to fixed positions, but when I implement the rotation so the camera can keep looking at the same spot, it calculates it wrong, how can I go around doing that?

 //Posiciones Actuales
         FVector camCurrentPos = mainCamera->GetActorLocation();
         FRotator camCurrentRot = mainCamera->GetActorRotation();
         //Posiciones Futuras
         FVector camMoveToPos;
         FRotator camRotateToPos;
         if (cameraMove == CameraMovement::Fixed)
             switch (cameraPosition)
             case CameraPosition::Front:
                 camMoveToPos = FVector(0.0f, 900.0f, 900.0f);
                 camRotateToPos = FRotator(0.0f, -45.0f, -90.0f);
             case CameraPosition::Right:
                 camMoveToPos = FVector(900.0f, 0.0f, 900.0f);
                 camRotateToPos = FRotator(0.0f, -45.0f, -180.0f);
             case CameraPosition::Back:
                 camMoveToPos = FVector(0.0f, -900.0f, 900.0f);
                 camRotateToPos = FRotator(0.0f, -45.0f, -270.0f);
             case CameraPosition::Left:
                 camMoveToPos = FVector(-900.0f, 0.0f, 900.0f);
                 camRotateToPos = FRotator(0.0f, -45.0f, -360.0f);
         else if (cameraMove == CameraMovement::Free)
         mainCamera->SetActorLocation(FMath::VInterpTo(camCurrentPos, camMoveToPos, DeltaSeconds, cameraMovSpeed));
         mainCamera->SetActorRotation(FMath::RInterpTo(camCurrentRot, camRotateToPos, DeltaSeconds, cameraMovSpeed).Quaternion());

this is the code I have for the movement and rotation. thank you.

avatar image Matthew J Jan 15 '16 at 06:51 PM

In what ways are the calculations wrong? I'll need to know how it is messing up to have an idea of why it is working incorrectly.

avatar image WolfAlvein Jan 15 '16 at 07:52 PM

Well instead of looking at the position indicated it ends up looking anywhere like Rotation X: 170, Y: 20, Z: 90 or something like that, what can I post so you can get a better idea?

avatar image Matthew J Jan 15 '16 at 08:44 PM

As the values are going to a positive value, this is a factor of quaternions and rotation in the engine. If you watch the value as it goes (It may help to use the "slomo" console command at .5 or a lower value to slow everything down) and it reaches a certain point, it'll cause some weird stuff to occur.

As an example, if you rotate along the Z axis outside of the bounds of -90 to 90, the value will reset to the opposite side of that range and change the other values to compensate.

This is a limitation of 3D rotation in the engine due to Quaternion math. I would suggest converting all of your values to Radians prior to doing calculations as they won't do that to you and you can convert them back to degrees afterwards.

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

1 answer: sort voted first

Hi Matthew thank you for the info but at the end it wasn't a problem with degrees or radians, it was in the way I formatted the data, since i used this FRotator(0.0f, -45.0f, -360.0f) instead of this FRotator(-45.0f, -360.0f, 0.0f), so the data was being assigned to the camera wrongly, but I still converted everything into radians and then back to degrees so there won't be any more problems with that. thank you.

more ▼

answered Jan 16 '16 at 09:07 AM

avatar image

23 14 17 22

(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