DEV Community

Maciej Sawicki
Maciej Sawicki

Posted on

[Game of Purpose] Day 54

Today I was working on using Cpp files as components. And I managed to do it. However, it is not that easy as it is in blueprints. In blueprints all the async execution flow is very seamless. However, in Cpp it seems to be harder.

Here I made a target go to the first point in a Spline.

void USplineNavigator::NavigateToSplinePoint()
{
    PrintString(TEXT("NavigateToSplinePoint"));
    check(targetSpline != nullptr);

    auto targetSplineTotalLength = targetSpline->GetSplineLength();

    // staring the movement
    if (NextTargetDistance < 0.0f)
    {
        NextTargetDistance = 0.0f;
    }
    // looping
    else if (targetSplineTotalLength >= NextTargetDistance)
    {
        NextTargetDistance = 0.0f;
    }
    else
    {
        NextTargetDistance = FMath::Clamp(NextTargetDistance + DistanceToMove, 0.0f, targetSplineTotalLength);
    }

    auto targetWorldLocation = targetSpline->GetLocationAtDistanceAlongSpline(
        NextTargetDistance, ESplineCoordinateSpace::World);


    AAIController* AIController = Cast<AAIController>(GetOwner()->GetInstigatorController());

    if (AIController == nullptr)
    {
        PrintString(TEXT("AIController is null"));
        return;
    }

    UAIBlueprintHelperLibrary::SimpleMoveToLocation(AIController, targetWorldLocation);
}

Enter fullscreen mode Exit fullscreen mode

Drawing debug arrows doesn't seem to work at all.

DrawDebugDirectionalArrow(
    GetOwner()->GetWorld(),
    FVector(0.0f, 0.0f, 0.0f),
    FVector(1500.f, 1500.f, 300.f),
    100.0f,
    FColor::Red,
    false,
    100,
    1,
    10.0f
);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)