任务:将摄像头绑定在弹簧臂上以获得更平滑的摄像机视角(另在Creature.cpp中设置球形根结点和默认静态网格体)
Creature.h新增代码如下:
public:
//新增球形组件
UPROPERTY(EditAnyWhere)
class USphereComponent* SphereComponent;
//新增弹簧臂组件
UPROPERTY(EditAnywhere)
class USpringArmComponent* SpringArm;
Creature.cpp关键代码如下:
ACreature::ACreature()
{
……
//初始化球形网格体,并将其设置为根组件
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
RootComponent = SphereComponent;
SphereComponent->InitSphereRadius(100.f);
SphereComponent->SetCollisionProfileName(TEXT("Pawn"));
//初始化静态网格体,并将静态网格体的默认值设置为SphereAsset
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
StaticMesh->SetupAttachment(RootComponent);
static Constru