VInterpTo not smoothly moving camera

Hey guys! Sorry to bother you all but I’m finding it extremely difficult to pinpoint this problem. I’ve tried searching online, posted in the answer hub but none of us were able to come up with a solution. I have a VInterpTo which should be smoothly moving a camera from one point to another in relative space. Although the camera moves to the specified location, it jumps to it - teleports. Here is the code:


void ATheMeadowsCharacter::SwitchCamera()
 {
     currentCameraPos = cameraTransformA;
     cameraSwitch = !cameraSwitch;
 
     if (cameraSwitch == false)
     {
         cameraTransformA.X = 20.0f;
         cameraTransformA.Y = 40.0f;
         cameraTransformA.Z = 40.0f;
     }
     else if (cameraSwitch == true)
     {
         cameraTransformA.X = 20.0f;
         cameraTransformA.Y = -40.0f;
         cameraTransformA.Z = 40.0f;
     }
 
     isSwitchedCamera = true;
 }
 
 void ATheMeadowsCharacter::Tick(float DeltaSeconds)
 {
     Super::Tick(DeltaSeconds);
 
     if (isSwitchedCamera == true)
     {
         FVector finalCamPos = FMath::VInterpTo(currentCameraPos, cameraTransformA, DeltaSeconds, 0.5f);
         FollowCamera->SetRelativeLocation(finalCamPos);
     }
 }

I tried debugging the code and found both values: currentCameraPos and cameraTransformA were indeed different. When I stepped into the VInterpTo function, the values were as expected with the InterpSpeed being 0.5. If anybody could help then I would be forever grateful.

Thanks!

Well after about 6 hours of me and mrooney debugging, he was able to figure out the problem - there is nothing actually increasing the delta time therefore it always stays at 0.008333 seconds. So in order for this to work we have to implement an accumulator. Here is the new code:


void ATheMeadowsCharacter::SwitchCamera()
{
	currentCameraPos = cameraTransformA;
	cameraSwitch = !cameraSwitch;

	if (cameraSwitch == false)
	{
		cameraTransformA.X = 20.0f;
		cameraTransformA.Y = 40.0f;
		cameraTransformA.Z = 40.0f;
	}
	else if (cameraSwitch == true)
	{
		cameraTransformA.X = 20.0f;
		cameraTransformA.Y = -40.0f;
		cameraTransformA.Z = 40.0f;
	}
	_accumulatorFloat = 0.0f;
	isSwitchedCamera = true;
}

void ATheMeadowsCharacter::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	if (isSwitchedCamera == true)
	{
		_accumulatorFloat += DeltaSeconds;
		FVector finalCamPos = FMath::VInterpTo(currentCameraPos, cameraTransformA, _accumulatorFloat, 0.5f);
		FollowCamera->SetRelativeLocation(finalCamPos);
	}
}

The simplest things seem to always be the hardest haha, I hope this will help anyone who comes across it :slight_smile: Big shoutout to mrooney for helping me!

Generally you should use Interop funcs with starting point as previous result of interop func. like

After typing I received some more help from a different guy on the answer hub explaining that using the method you’ve described is much better. Using mine is basically a multiplier for speed which would result in hugely different results for different PCs.