hi,
i have a setup where i have
- 1 controller that just takes input and moves a pawn accordingly, free cam style.
- 1 pawn, that is moved by the controller. a APawn without any changes
- multiple cameras that can be switched, where the current camera should move with the pawn, the others not.
here is how the switching works:
void ALVJPlayerController::SetCamera(ACameraActor* Cam)
{
if (IsValid(Camera))
{
FDetachmentTransformRules Rules(EDetachmentRule::KeepWorld, true);
Camera->DetachFromActor(Rules);
}
LVJCamera = Cast<ALVJCineCameraActor>(Cam);
Camera = Cam;
APawn* CurrentPawn = GetPawnOrSpectator();
if (IsValid(CurrentPawn))
{
//this is a hack to avoid the new camera to receive the last camera's
//last movement. this happens for (yet) unknown reason.
//the static flag is cleared on camera tick by the camera if it is not
//locked
Cam->GetRootComponent()->SetMobility(EComponentMobility::Static);
CurrentPawn->SetActorTransform(Cam->GetTransform(), false, nullptr, ETeleportType::TeleportPhysics);
FAttachmentTransformRules Rules(EAttachmentRule::KeepWorld, false);
Cam->AttachToActor(CurrentPawn, Rules);
}
SetViewTarget(Camera);
}
so i detach the old camera, then attach the new camera to the pawn, then set the controller’s view target.
the problem is, this does ONLY work when i have this added.
//this is a hack to avoid the new camera to receive the last camera's
//last movement. this happens for (yet) unknown reason.
//the static flag is cleared on camera tick by the camera if it is not
//locked
Cam->GetRootComponent()->SetMobility(EComponentMobility::Static);
otherwise every camera is moved to the position of the previous camera on switch. i don’t understand why this is happening and why this line helps. because this sets the new camera to locked and not the old one…
i also tried to delay the attachment of the new camera for 40 ticks or so, which resulted in the same behavior. when the ticks are over and the attach of the new camera is called it immediately changes the pawn and camera transform to the transform of the previous camera.
can somebody enlighten me?