I have been trying to use splines in C++ to spawn a set of actors randomly along the curve of a spline.
So far all I have achieved is making a straight line with all of the actors being spawned at the endpoint.
I want the top spline, but can only seem to achieve the bottom spline.
{
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComp"));
SpawningSpline = CreateDefaultSubobject<USplineComponent>(TEXT("Path"));
SpawningSpline->SetupAttachment(RootComponent);
}
for (size_t i = 0; i < ActorCount; i++)
{
SpawningSpline->ClearSplinePoints();
FSplinePoint StartPoint;
FSplinePoint EndPoint;
StartPoint.InputKey = 0.0;
StartPoint.Position = StartLoc;
StartPoint.ArriveTangent = FVector(100.0F, 0.0F, 0.0F);
StartPoint.LeaveTangent = FVector(100.0F, 0.0F, 0.0F);
StartPoint.Rotation = StartDir.Rotation();
StartPoint.Type = ESplinePointType::Curve;
EndPoint.InputKey = 1.0;
EndPoint.Position = StartPoint.Position + (EndDir * Distance);
EndPoint.ArriveTangent = FVector(100.0F, 0.0F, 0.0F);
EndPoint.LeaveTangent = FVector(100.0F, 0.0F, 0.0F);
EndPoint.Rotation =FRotator(0.0F, 135.0F, 0.0F);
EndPoint.Type = ESplinePointType::Curve;
SpawningSpline->AddPoint(StartPoint, true);
SpawningSpline->AddPoint(EndPoint, true);
SpawnLocation = SpawningSpline->GetWorldLocationAtDistanceAlongSpline(FMath::FRandRange(0.0F, SpawningSpline->Duration));
}
What do I need to do to achieve the following:
- Give the Spline a curve
- Get a SpawnLocation that isn’t the Start or End Point, but rather a random location along the curve between the Start and End Point.
Any help with this would very much be appreciated.