How can I know if there is something blocking on the location I'm going to move with interpolation?

Hi!

I’m using 5.3.2.

I have used the following instruction to move a pawn, and it works perfectly:

SetActorLocation(GetNewLocation(), true, &OutSweepHitResult);

But, know I want to use interpolation.

How can I know if there is something blocking the movement at the location I want to move before start moving the pawn with interpolation?

Thanks!

Before you even move, fire a single (line/box/sphere) trace from where you are to the location. If you get a False, it’s clear.


Another way is to use the actual Sweep. Before you move, place the actor in the target location with Sweep enabled.

  • if Sweep returns True (&OutSweepHitResult), it bumped into something, move it back to the starting location and do not move
  • if Sweep returns False, the path is clear, move it back and start interpolating

This is much more expensive but you are sweeping with the entire actor, if it has parts sticking out that could catch on some geometry, you’ll know. Sweep is not perfect over great distances and may miss thin obstacles.

1 Like

But the player will see the pawn moving forward and backward, isn’t it? Or maybe not.

Thanks!

Nah, it all happens before the frame gets rendered. You can do at least 2 things in the same frame :stuck_out_tongue: Games are smoke & mirrors, anyway.

When you start interpolating, Set Actor Location without Sweep - since you know the coast is clear.


I’d roll with a line / box / sphere trace tbh, until it cannot do the job.

1 Like

I’ve done it this way:

void ARSRobotPawn::Move(float Value)
{
	if ((!bIsMoving) && (!bIsRotating))
	{
		if (TObjectPtr<UWorld> World = GetWorld())
		{
			const FVector Start = GetActorLocation();
			const FVector End = Start + (Value * GridCellSize * GetActorForwardVector());
			FHitResult OutHit;

			if (!World->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility))
			{
				bIsMoving = true;

				DestinationLocation = End;
			}
		}
	}
}

Thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.