I went about it slightly differently

I figured the direction and length vector is going to be the same in local space just offset in world space and wont change after play as the widget can’t be moved at that point.

So in begin play I get the direction and length of the vector from the objects root in local which is 0,0,0 then add the actors world location to the result for the final target location.

Then in tick I used VInterpConstantTo to move to the target location at whatever constant speed we want.

Seems to work but we will see if I get caught out later :slight_smile:

#include "MovingPlatform.h"

AMovingPlatform::AMovingPlatform()
{
	//Constructor
	PrimaryActorTick.bCanEverTick = true;
	SetMobility(EComponentMobility::Movable);
}

void AMovingPlatform::BeginPlay()
{
	Super::BeginPlay();
	//do it on begin play not construct as construct can happen too early.
	if (HasAuthority())
	{
		SetReplicates(true);
		SetReplicateMovement(true);

		//CurrentLocation will be 0,0,0 in local Space
		TargetVector = (TargetLocation - CurrentLocation);
		
		//Get the noirmalised Direction and also how long the vector is as a float
		TargetVector.ToDirectionAndLength(NormalisedVectorDirection, VectorLength);

		//Add World Location offset of Actor Root being in local space.
		TargetLocation = NormalisedVectorDirection * VectorLength + GetActorLocation();

	}

}

void AMovingPlatform::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (HasAuthority())
	{
		WorldLocation = GetActorLocation();

		//Constent Lerp to location Speed is UPROPERTY
		//FMath::VInterpTo for nice fade to stop perhaps use later
		LerpLocation = FMath::VInterpConstantTo(WorldLocation, TargetLocation, DeltaTime, Speed);

		SetActorLocation(LerpLocation);
	}
}
1 Like

Try rotating your MovingPlatform actor and see what happens. Does the MovingPlatform still go to the target location?

1 Like

Privacy & Terms