I setup a simple TArray of TargetLocations and have been able to cycle through the Array successfully. However, the positions are wrong. TargetLocation[0] is correct, TargetLocation[1] is correct, after that subsequent TargetLocations are incorrect.
I’m not going to copy the whole code, just my changes from the lessons:
if (JourneyTravelled > JourneyLength)
{
/* FVector Swap = GlobalStartLocation;
GlobalStartLocation = GlobalTargetLocation;
GlobalTargetLocation = Swap;
*/
GlobalStartLocation = GlobalTargetLocation;
if (TargetLocationIndex == TargetLocation.Num() - 1)
{
TargetLocationIndex = 0;
}
else
{
TargetLocationIndex += 1;
}
GlobalTargetLocation = GetTransform().TransformPosition(TargetLocation[TargetLocationIndex]);
//GlobalTargetLocation = TargetLocation[TargetLocationIndex];
}
Where am I going wrong? The TargetLocation is determined globally not locally.
Please help.
TargetLocation[0] = GetActorLocation() in BeginPlay, the platform location in world space
TargetLocation[1] is in local space in relation to initial spawn location (world space) of the platform
TargetLocation[n] should follow the same concept, where each additional TargetLocation is in local space relative to the initial spawn location of the platform.
Therefore, converting each TargetLocation[n] to world space via GetTransform().TransformPosition(TargetLocation[n]) should place the TargetLocation at its world position relative to its local position. Essentially the same position, just in different spaces. One relative to world origin, the other relative to platform origin.
However, this is not happening. TargetLocations beyond TargetLocation[1] are not where they should be. They are in very different locations as the platform moves from index to index in the array.
I’ve tried adding, subtracting, and multiplying various FVectors. I can get close, but never quite there. Close meaning the path is correct, but the positions are all wrong.
Any thoughts? Anyone?