Download

Help with Orbit Camera with mouse (not using springarm)

So I’m programming my own camera orbit because I want collision only on the camera and spring arm can’t do that. Here is what I have so far:



void AMyPlayerController::EnableRotate() { lastRotationVector = puzzleCamera->GetActorLocation() - cameraRotationPoint;
lastRotationVector.Normalize();
rotateEnabled = true;
 }
void AMyPlayerController::MouseTurn(float Rate) { if (rotateEnabled) {
  [INDENT=2]FVector rotateReturned = lastRotationVector.RotateAngleAxis(Rate * 3, FVector::UpVector);
rotateReturned.Normalize();
puzzleCamera->SetActorLocation(cameraRotationPoint + (rotateReturned*zoomDistance), true);
lastRotationVector = rotateReturned;
puzzleCamera->SetActorRotation((-rotateReturned).Rotation());[/INDENT]
  }
 }

void AMyPlayerController::MouseLookUp(float Rate) { if (rotateEnabled) {
  [INDENT=2]FVector rotateReturned = lastRotationVector.RotateAngleAxis(Rate * 3, FVector::ForwardVector);
rotateReturned.Normalize();
puzzleCamera->SetActorLocation(cameraRotationPoint + (rotateReturned*zoomDistance), true);
lastRotationVector = rotateReturned;
puzzleCamera->SetActorRotation((-rotateReturned).Rotation());[/INDENT]
  }
 }


EnableRotate is called when you press the right mouse button down.
cameraRotationPoint is the vector I want it to rotate around.

So far it works for MouseTurn but MouseLookUp only works on one direction. I’m not sure how to change ForwardVector so it doesn’t get flipped around when rotation is changed. It currently only works when looking from one side.