Requestdirectmove() and movetoactor()

Can someone explain how requestdirectmove() and movetoactor() are related and what movetoactor() actually does?

ok just rewatched videos. movetoactor gives data to requestdirectmove every frame so it knows what direction to move and requestdirectmove is what actually moves the tank. we also overrided the requestdirectmove so that it uses our movement component instead of the default one. its the complicated stuff thats easy to use that confuses me sometimes.

Basically MoveToActor will call a bunch of other functions in the AIController which in a nutshell finds the path and sets some data. Then in the MovementComponent will eventually call RequestDirectMove every tick.

This next part isn’t important to understand I just thought it would be nice addition.
Here is the function that eventually calls RequestDirectMove

void UPathFollowingComponent::FollowPathSegment(float DeltaTime)
{
	if (!Path.IsValid() || MovementComp == nullptr)
	{
		return;
	}

	const FVector CurrentLocation = MovementComp->GetActorFeetLocation();
	const FVector CurrentTarget = GetCurrentTargetLocation();

	const bool bAccelerationBased = MovementComp->UseAccelerationForPathFollowing();
	if (bAccelerationBased)
	{
		CurrentMoveInput = (CurrentTarget - CurrentLocation).GetSafeNormal();

		if (MoveSegmentStartIndex >= DecelerationSegmentIndex)
		{
			const FVector PathEnd = Path->GetEndLocation();
			const float DistToEndSq = FVector::DistSquared(CurrentLocation, PathEnd);
			const bool bShouldDecelerate = DistToEndSq < FMath::Square(CachedBrakingDistance);
			if (bShouldDecelerate)
			{
				const float SpeedPct = FMath::Clamp(FMath::Sqrt(DistToEndSq) / CachedBrakingDistance, 0.0f, 1.0f);
				CurrentMoveInput *= SpeedPct;
			}
		}

		PostProcessMove.ExecuteIfBound(this, CurrentMoveInput);
		MovementComp->RequestPathMove(CurrentMoveInput);
	}
	else
	{
		FVector MoveVelocity = (CurrentTarget - CurrentLocation) / DeltaTime;

		const int32 LastSegmentStartIndex = Path->GetPathPoints().Num() - 2;
		const bool bNotFollowingLastSegment = (MoveSegmentStartIndex < LastSegmentStartIndex);

		PostProcessMove.ExecuteIfBound(this, MoveVelocity);
		MovementComp->RequestDirectMove(MoveVelocity, bNotFollowingLastSegment);
	}
}

Here at the very last line is where that RequestDirectMove finally gets called.

1 Like

thanks. thank god for game engines that do all this stuff for us.

Privacy & Terms