How to set location of Spring Arm in C++?

I want to set the relative location for the spring arm in C++ , any help appreciated )

blueprint version.

I tried this but not working: :frowning:

SpringArm->SetRelativeLocation(Location);
NewLocation = FVector(Location.x, Location.y, Location.z + ReturnValue);
SetActorLocation(FMath::Lerp(Location, NewLocation, ReturnValue));

This is how the function looks like in the source code, but not available using SpringArm->GetRelativeLocation();

/**
 * Gets the literal value of RelativeLocation.
 * Note, this may be an absolute location if this is a root component (not attached to anything) or
 * when IsUsingAbsoluteLocation returns true.
 *
 * This exists so subclasses don't need to have direct access to the RelativeLocation property so it
 * can be made private later.
	 */
	FVector GetRelativeLocation() const
	{
		return RelativeLocation;
	}

The lerps in your examples seem incorrect. In the BP example, your lerp alpha being 0 will return Location… New Location will be ignored. In the C++ example, you use returnvalue for the location and alpha so it’s difficult to understand what you’re doing there.

Alpha generally is a range 0.0 - 1.0. 0 will return the first value, 1 will return the second, 0.5 will return a value halfway between the two (Linear Interpolated ie Lerp).

1 Like
			 fvectorlocation = SpringArm->GetComponentLocation();
             FMath::Lerp(fvectorlocation, fvectornewlocation, output);
			 SpringArm->SetRelativeLocation (fvectornewlocation = FVector(fvectorlocation.X , fvectorlocation.Y, fvectorlocation.Z + output));
			 

I hope it will help you , cheers.

1 Like

yes but send me to the moon :smiley: well at least I learned how to change the location of the components, Thank You for your reply but still not solved the issue

Thank You for helping, at least I learned something new about lerp )

edit has been made to my post, corrected the overflow.

1 Like

Thank You for helping, very much appreciated )

1 Like

No problem, keep coding and learning.

1 Like