【问题标题】:Unreal engine 5 set world rotation虚幻引擎5设置世界旋转
【发布时间】:2022-10-22 23:54:49
【问题描述】:

我目前正在尝试复制一个非常简单的教程,用于在虚幻引擎 5 中设置 2D 平台游戏。我想在 C++ 中复制蓝图方式。但是,我无法设置带有附加相机的弹簧臂组件的绝对旋转。从 cpp 代码中,我创建了一个蓝图并成功编译了所有内容。但是,改变旋转不会。

我的代码是什么样的:

#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);

}

不幸的是,我还尝试设置不同的东西,但没有成功:

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

它只是没有改变任何东西,也没有发生任何事情。 这两天我似乎找不到原因。更改 targetarmlength 也有效。任何提示都非常感谢。

下面是相应的标题:

#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;

};

【问题讨论】:

    标签: c++ unreal-engine5


    【解决方案1】:

    尝试创建一个 SceneComponent,将其附加到 RootComponet,然后将 USpringArmComponent 附加到 SceneComponent,然后对 SceneComponent 进行所有转换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      • 2022-06-13
      • 2023-02-19
      • 1970-01-01
      相关资源
      最近更新 更多