// Called when the game starts or when spawned
void ABaseObs::BeginPlay()
{
Super::BeginPlay();
this->Root->OnComponentHit.AddDynamic(this, &ABaseObs::OnCompHit);
this->SetLifeSpan(180.0);
// GetWorld()->GetTimerManager().SetTimer(this->TimerHandle, this, &ABaseObs::WhatToDO, 0.1f, true);
this->StartLocation=this->GetActorLocation();
this->EndLocation=this->TargetLocation->GetComponentLocation();
state = STATE::UP;
}
// Called every frame
void ABaseObs::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
switch (state)
{
case STATE::UP:
{
[&]()
{
UE_LOG(LogTemp, Warning, TEXT("Going up..."))
if (GetActorLocation().Size() <= EndLocation.Size()-0.01)
{
FVector NewLocation = FMath::Lerp(GetActorLocation(),EndLocation, FloatSpeed);
SetActorLocation(NewLocation);
}
else
{
state = STATE::DOWN;
};
}();
break;
};
case STATE::DOWN:
{
[&]()
{
UE_LOG(LogTemp, Warning, TEXT("Going down..."))
if (GetActorLocation().Size()> StartLocation.Size()+0.01)
{
FVector NewLocation=FMath::Lerp(GetActorLocation(), StartLocation,FloatSpeed);
SetActorLocation(NewLocation);
}
else
{
state = STATE::UP;
};
}();
break;
};
}
};
1 Like
Could you be a little more descriptive? In what way? Is it randomly? Anything specific? Also how is it not working?
P.S. what’s the reason for the immediately invoked lambda?