首页 > 解决方案 > UE4 C++:无法在圆形路径中移动 Actor

问题描述

我正在使用虚幻引擎 4.25。我正在尝试在圆形路径中移动一个球体 Actor。然而,球体只能沿直线来回移动。

这是 MyActor.cpp 代码:

#include "MyActor.h"
#include "Materials/MaterialInstanceDynamic.h" 
#include "Components/StaticMeshComponent.h"

// Sets default values
AMyActor::AMyActor()
{
    // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;



    Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
    RootComponent = Root;

    Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
    Mesh->AttachTo(Root);

    Dimensions = FVector(30, 0, 0);
    AxisVector = FVector(0.01, 0.01, 0);
    Location   = FVector(0.1, 0.1, 0.1);
    Multiplier = 50.f;
}

// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
    Super::BeginPlay();
}

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    // Updates the angle of the object
    AngleAxis += DeltaTime * Multiplier;

    if (AngleAxis >= 360.0f)
    {
        AngleAxis = 0;
    }

    //Rotates around axis
    FVector RotateValue = Dimensions.RotateAngleAxis(AngleAxis, AxisVector);

    Location.X += RotateValue.X;
    Location.Y += RotateValue.Y;
    Location.Z += RotateValue.Z;

    SetActorLocation(Location, false, 0, ETeleportType::None);

}

如果我需要添加更多信息,请告诉我。

免责声明:我对 UE4 完全陌生。如果这是一个愚蠢的问题,我很抱歉。

标签: c++animationgraphicsunreal-engine4game-development

解决方案


推荐阅读