Send Platform Back

I did this a bit different using a flag if it passed the end and then flipped if I was adding or subtracting the vector to the Location.

if (HasAuthority()) {

		FVector Location = GetActorLocation();
		FVector Direction = (GlobalTargetLocation - Location).GetSafeNormal();

		float Length = (GlobalTargetLocation - GlobalStartLocation).GetSafeNormal().Size();
		float DistanceFromStart = (Location - GlobalStartLocation).Size();
		float DistanceFromEnd = (Location - GlobalTargetLocation).Size();
		
		if (Length > DistanceFromStart) {
			MoveTo = false;
		}

		else if (Length > DistanceFromEnd) {
			MoveTo = true;
		}
			
		Location = (MoveTo) ? Location - (MovementSpeed * DeltaTime * Direction) : Location + (MovementSpeed * DeltaTime * Direction);
		SetActorLocation(Location);
	}

Wish I my brain would have thought to simply swap the variable out lmao nevermind

1 Like

The length will always be 1.0f because you’re getting the size of the normal and a normal is always length 1.

There are a few things here.

first, the platform might never quite reach the end - within tolerance it flips and moves in the opposite end. Ideally, the platform should move the exact start or end position depending of direction of travel.

Second, if you use a target position variable, you can get the direction vector between current position and the target. If the size < tolerance, snap to the target otherwise get the normal and multiply by the speed and you add this to the current platform position.

This is a more involved process but enables you to define multiple movement points via an array, theoretically thus expanding the game. However you can just track as you do with the boolean and on reaching the end, change the target back to the start position.

I hope this makes sense.

1 Like

Thanks for this and makes perfect sense!

1 Like

Privacy & Terms