I need to interpolate two locations and I do it with VInterpTo. I use it to update the position of a camera after a collision. It works great but then I need to stop the interpolation because i want to update the camera every tick without any interpolation when a collision is not happening.
I don’t want to check the distance because it wouldn’t be accurate enough and I have seen that FVector::equals, even with a large tolerance, doesn’t give me a good resulting behaviour.
Unfortunately I don’t have have a computer with UE4 now but in pseudo code it looks like this:
FVector finalCameraLoc = ....location where the camera should be;
FHitResult hit;
TraceForCheckingCollision( hit, .... );
// handle collision
if( hit.bBlockingHit )
{
// directly set the camera where the collision happens
outVT.POV.Location = hit.Location;
bIsColliding = true;
}
// no collision
else
{
// it was collising in the tick before, want to return in position smoothly
if( bIsColliding )
{
// smootly move the camera back in position
outVT.POV.Location = VInterp(outVT.POV.Location, finalCameraLoc, ...);
if( INTERPOLATION IS FINISHED ) // don't know how to do this part
{
bIsColliding = false;
}
}
else
{
// Normal case, no collision happening and no precedent collision to handle
outVT.POV.Location = finalCameraLoc;
}
}
Do you have any suggestion about how to implement this?