1205
(1205)
February 9, 2016, 2:26pm
1
in Unreal Tutorial, PlayerCharacter has CameraComponent and SpringArmComponent
So at SpringArmComponent->bUsePawnControlRotation = false,
Pawn is same PlayerCharacter, Directly Connect.
but in my code, something is difference and the difference makes a problem.
MyCharacter has AMyCameraActor Class as member value point like this.
MyPlayerCharacter.h
AMyCameraActor* m_pCameraActor;
also, this AMyCameraActor has CameraComponent and SpringArmComponent.
resultingly between AMyCharacter and SpringArmComponent, middle class exist “AMyCameraActor”.
it seem good, in my opinion.
but problem is about “bUsePawnControlRotation” .
because AMyCameraActor has SpringArmComponent, SpringArmComponent’s Pawn is AMyCameraActor not AMyCharacter.
although i set bUsePawnControlRotation false
it doesn’t work
how to handle this matter?
1205
(1205)
February 9, 2016, 2:55pm
2
of course, I set values in AMyCharacterScript
GetCharacterMovement()->bOrientRotationToMovement = true;
bUseControllerRotationYaw = false;
bUseControllerRotationPitch = false;
bUseControllerRotationRoll = false;
1205
(1205)
February 9, 2016, 3:23pm
3
//ACamera.h
UCLASS()
class FRAMEWORK_API AFrameWorkCamera : public AActor
{
GENERATED_BODY()
public:
UCameraComponent* m_pCameraCom;
USpringArmComponent* m_pSpringArm;
public:
AFrameWorkCamera();
virtual void BeginPlay() override;
virtual void Tick( float DeltaSeconds ) override;
};
//ACamera.cpp
AFrameWorkCamera::AFrameWorkCamera()
: Super()
{
PrimaryActorTick.bCanEverTick = true;
m_pSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("OurCamera"));
m_pSpringArm->AttachTo(RootComponent);
m_pSpringArm->bAbsoluteRotation = true;
m_pSpringArm->TargetArmLength = 800.f;
m_pCameraCom = CreateDefaultSubobject("CameraComponent");
m_pCameraCom->AttachTo(m_pSpringArm);
m_pCameraCom->bUsePawnControlRotation = false;
}
//ACharacter.h
UCLASS()
class FRAMEWORK_API AFrameWorkCharacter : public ACharacter
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
AFrameWorkCamera* m_pCamera;
public:
…
};
//ACharacter.cpp
void AFrameWorkCharacter::BeginPlay()
{
Super::BeginPlay();
if (!m_pCamera)
{
FVector ActorLocation = this->GetActorLocation();
FVector RelativeLocation = FVector(
ActorLocation.X,
ActorLocation.Y,
ActorLocation.Z);
m_pCamera= (AFrameWorkCamera*)GetWorld()->SpawnActor(AFrameWorkCamera::StaticClass(),
&RelativeLocation);
m_pCamera->AttachRootComponentToActor(this);
APlayerController* OurPlayerController = UGameplayStatics::GetPlayerController(this, 0);
if(OurPlayerController)
OurPlayerController->SetViewTargetWithBlend(m_pCamera, 0.75f);
}
}
1205
(1205)
February 9, 2016, 3:28pm
4
Code is so simple,
Character has CameraActor
and
CameraActor has two Component(Camera,SpringArm)
Hey 1205-
What class is AMyCameraActor based on? Can you post the full code for the AMyCameraActor class so that I can ensure my setup matches what you’re using?
The easiest solution would be to add the SpringArmComponent and the CameraComponent directly to the character rather than adding them to another class/component that is then being added.
Cheers
1205
(1205)
February 9, 2016, 3:30pm
6
i am finding problem solution, staying this class structure… T-T
1205
(1205)
February 9, 2016, 3:45pm
7
ah, i add code m_pCamera->AttachRootComponentToActor(this) in Character’s BeginPlay
1205
(1205)
February 9, 2016, 3:50pm
8
i change upper comment code
Hey 1205-
Were the changes you made enough to get the camera working correctly for you? If you are still having problems with the camera setup then I would suggest adding the camera component and the spring arm component directly to the character class and using CreateDefaultSubobject in the character constructor for both.
Cheers