Enable camera lag on spring arm only for collisions

I have a spring arm component attached to my pawn for a third person shooter. Most of the time I do not want to have camera lag on it, because this would affect the aim/shoot mechanic. I do want it however for collisions, because in some environments it causes the spring arm to jitter due to collisions of different meshes at the same time.

Is there an event I can hook into to enable/disable this or any other solution for this problem?

Hi,

If you take a look inside SpringArmComponent.cpp you will see alsmot at the end of the function UpdateDesiredArmLocation that after perform the Trace to detect the collision the function BlendLocation is called to get the final location.

So, you just need to create a new SpringArmComponent extending from this one, and override this function:

FVector USpringArmComponent::BlendLocations(const FVector& DesiredArmLocation, const FVector& TraceHitLocation, bool bHitSomething, float DeltaTime)
{
	return bHitSomething ? TraceHitLocation : DesiredArmLocation;
}

Instead of return TraceHitLocation directly, you should interp from the current DesiredArmLocation to TraceHitLocation.

I haven’t tried this but should work

Best regards

For other people who are interested: in the overridden function I used it to set the lag on and off.

FVector USpringArmComponentBase::BlendLocations(const FVector& DesiredArmLocation, const FVector& TraceHitLocation, bool bHitSomething, float DeltaTime)
{
	if (bHitSomething)
	{

		this->CameraRotationLagSpeed = 1.5f;
		this->bEnableCameraRotationLag = true;
	}
	else
	{
		this->bEnableCameraRotationLag = false;
	}

	return bHitSomething ? TraceHitLocation : DesiredArmLocation;
}