Hello everyone,
Starting from a blank project I created some “cube” pawns that wander around.
Now I would like to be able to incarnate a cube and have a top-down camera, but failed to succeed.
First I tried to put a CameraComponent attached to a SpringArmComponent on my PlayerController, but it did not worked: I still had the default, looking forward, camera (not the top-down-spring-arm I configured).
AMyPlayerController::AMyPlayerController()
{
SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
SpringArmComp->SetupAttachment(RootComponent);
CameraComp->SetupAttachment(SpringArmComp, USpringArmComponent::SocketName);
SpringArmComp->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, 0.0f), FRotator(-40.0f, 0.0f, 0.0f));
SpringArmComp->TargetArmLength = 900.f;
SpringArmComp->bEnableCameraLag = true;
SpringArmComp->CameraLagSpeed = 3.0f;
}
If i possess the pawn cube with the code below, I have a FPS camera and not the top-down one (FPS such as I’m inside the cube and look though its eyes).
// Incarnate the first actor found
auto it = TActorIterator<ACubePawn>(world);
for (; it; ++it)
{
this->Possess(*it);
// Not working either:
//this->SetViewTarget(*it);
break;
}
A second thing I tried was to extend my cube Pawn class with a blueprint to add the SpringArm and the CameraComponent, as well as enabling auto possess player 0.
This time, I have the correct camera but it seems that the StaticMesh (the cube) is moved to the same location as the camera. I should like at it, but instead it disappear (but I can see its shadow).
Any idea of what I’m doing wrong? How to dynamically set the SpringArm to follow a Pawn?
Thanks, have a nice day!