I have a Background Block Actor that is always moving to the left in the background of the screen. It consists of a static mesh and a decal with the background image. I am trying to move it with a projectile movement component, but it just stays in place and doesn’t want to move. What am I missing?
UCLASS()
class MYGAME_API ABackgroundBlock : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ABackgroundBlock();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere)
class UStaticMeshComponent* mesh = nullptr;
UPROPERTY(EditAnywhere)
class UDecalComponent* decal = nullptr;
UPROPERTY(EditAnywhere)
class UProjectileMovementComponent* movement = nullptr;
UPROPERTY(VisibleAnywhere)
float speed = 400;
};
ABackgroundBlock::ABackgroundBlock()
{
// 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;
movement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("MovementComp"));
movement->ProjectileGravityScale = 0;
movement->Velocity = FVector(0, 0, 0);
mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshBottom"));
mesh->OnComponentBeginOverlap.AddDynamic(this, &ABackgroundBlock::teleport);
decal = CreateDefaultSubobject<UDecalComponent>(TEXT("Decal"));
decal->SetupAttachment(mesh);
}
// Called when the game starts or when spawned
void ABackgroundBlock::BeginPlay()
{
//movement->Velocity = FVector(0, -speed, 0);
//movement->InitialSpeed = speed;
//movement->MaxSpeed = movement->InitialSpeed;
}