prallina
prallina

Reputation: 1

Unreal engine 5 set world rotation

I'm currently trying to replicate a very simple tutorial for setting up a 2D platformer in unreal engine 5. I want to replicate the blueprint way in c++. However, I'm not able to set the absolute rotation of a springarm component with a attached camera. From the cpp code I created a blueprint and compiled everything successfully. However, changing the rotation doesn't.

What my code looks like:

#include "Hero_Paper_Character.h"

#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"

AHero_Paper_Character::AHero_Paper_Character() {
    SpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
    SpringArmComponent->SetupAttachment(RootComponent);
    SpringArmComponent->SetWorldRotation(FRotator(0.0f, -90.0f, 0.0f));
    SpringArmComponent->TargetArmLength = 550.f;
    SpringArmComponent->bEnableCameraLag = true;
    SpringArmComponent->CameraLagSpeed = 4.f;

    CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    CameraComponent->SetupAttachment(SpringArmComponent);

}

I also tried out to set different stuff unfortunately without any success:

    SpringArmComponent->SetUsingAbsoluteRotation(true);
    SpringArmComponent->AddWorldRotation(FRotator(0.0f, -90.0f, 0.0f));

It just doesn't change anything and nothing is happening. For two days I can't seem to find the reason why. Also changing targetarmlength is working. Any hints are highly appreciated.

Below is the corresponding header:

#include "CoreMinimal.h"

#include "PaperCharacter.h"

#include "Hero_Paper_Character.generated.h"

UCLASS()
class PLATFORMER_2D_API AHero_Paper_Character : public APaperCharacter
{
    GENERATED_BODY()
    
public:

    AHero_Paper_Character();

protected:

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
    class USpringArmComponent* SpringArmComponent;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
    class UCameraComponent* CameraComponent;

};

Upvotes: 0

Views: 2055

Answers (1)

forty_tw0
forty_tw0

Reputation: 35

First check if bUseControllerViewRotation is set, then try creating a SceneComponent, attaching that to the RootComponet, and then attaching your USpringArmComponent to the SceneComponent, then do all of your transformations to the SceneComponent.

Upvotes: 0

Related Questions