
Code:
FVector radiusVector = GetActorLocation() - target->GetActorLocation(); FVector CrossProd = FVector::CrossProduct(radiusVector, target->GetActorUpVector()); CrossProd.Normalize(); radiusVector = radiusVector.RotateAngleAxis(-rotSpeed*CurrentRotation.X, target->GetActorUpVector()); radiusVector = radiusVector.RotateAngleAxis(rotSpeed*CurrentRotation.Y, CrossProd); SetActorLocation(target->GetActorLocation() + radiusVector); FRotator rot = (target->GetActorLocation() - GetActorLocation()).Rotation(); GetController()->SetControlRotation(rot);
The rotation around the vertical axis is simple. But to rotate up and down we have to calculate an additional axis, which will be orthogonal to the plane constructed by Up-vector and radius-vector.
Then rotate the camera both in the Up-axis and the additional axis and set it looking at the model
Leave a comment: