mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 09:35:25 +00:00
Spring arm can now smoothly change socket / target offsets
This commit is contained in:
parent
2ecc91f554
commit
394f30251a
@ -9,11 +9,36 @@ UStevesSpringArmComponent::UStevesSpringArmComponent(): bEnableSmoothCollisionAv
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FVector UStevesSpringArmComponent::BlendLocations(const FVector& DesiredArmLocation,
|
void UStevesSpringArmComponent::UpdateDesiredArmLocation(bool bDoTrace,
|
||||||
const FVector& TraceHitLocation,
|
bool bDoLocationLag,
|
||||||
bool bHitSomething,
|
bool bDoRotationLag,
|
||||||
float DeltaTime)
|
float DeltaTime)
|
||||||
{
|
{
|
||||||
|
// Smooth target & socket offsets
|
||||||
|
if (SmoothTargetOffsetTarget.IsSet())
|
||||||
|
{
|
||||||
|
TargetOffset = FMath::VInterpTo(TargetOffset, SmoothTargetOffsetTarget.GetValue(), DeltaTime, SmoothTargetOffsetSpeed);
|
||||||
|
if (TargetOffset.Equals(SmoothTargetOffsetTarget.GetValue()))
|
||||||
|
{
|
||||||
|
CancelTargetOffsetSmooth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (SmoothSocketOffsetTarget.IsSet())
|
||||||
|
{
|
||||||
|
SocketOffset = FMath::VInterpTo(SocketOffset, SmoothSocketOffsetTarget.GetValue(), DeltaTime, SmoothSocketOffsetSpeed);
|
||||||
|
if (SocketOffset.Equals(SmoothSocketOffsetTarget.GetValue()))
|
||||||
|
{
|
||||||
|
CancelSocketOffsetSmooth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Super::UpdateDesiredArmLocation(bDoTrace, bDoLocationLag, bDoRotationLag, DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
FVector UStevesSpringArmComponent::BlendLocations(const FVector& DesiredArmLocation,
|
||||||
|
const FVector& TraceHitLocation,
|
||||||
|
bool bHitSomething,
|
||||||
|
float DeltaTime)
|
||||||
|
{
|
||||||
|
|
||||||
#if WITH_EDITORONLY_DATA && ENABLE_VISUAL_LOG
|
#if WITH_EDITORONLY_DATA && ENABLE_VISUAL_LOG
|
||||||
if (bHitSomething && bVisualLogCameraCollision)
|
if (bHitSomething && bVisualLogCameraCollision)
|
||||||
@ -49,7 +74,7 @@ FVector UStevesSpringArmComponent::BlendLocations(const FVector& DesiredArmLocat
|
|||||||
Ret += FRotationMatrix(PreviousDesiredRot).TransformVector(SocketOffset);
|
Ret += FRotationMatrix(PreviousDesiredRot).TransformVector(SocketOffset);
|
||||||
|
|
||||||
PrevArmLength = NewArmLen;
|
PrevArmLength = NewArmLen;
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -58,3 +83,25 @@ FVector UStevesSpringArmComponent::BlendLocations(const FVector& DesiredArmLocat
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UStevesSpringArmComponent::SetTargetOffsetSmooth(const FVector& NewTargetOffset, float Speed)
|
||||||
|
{
|
||||||
|
SmoothTargetOffsetTarget = NewTargetOffset;
|
||||||
|
SmoothTargetOffsetSpeed = Speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UStevesSpringArmComponent::CancelTargetOffsetSmooth()
|
||||||
|
{
|
||||||
|
SmoothTargetOffsetTarget.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UStevesSpringArmComponent::SetSocketOffsetSmooth(const FVector& NewSocketOffset, float Speed)
|
||||||
|
{
|
||||||
|
SmoothSocketOffsetTarget = NewSocketOffset;
|
||||||
|
SmoothSocketOffsetSpeed = Speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UStevesSpringArmComponent::CancelSocketOffsetSmooth()
|
||||||
|
{
|
||||||
|
SmoothSocketOffsetTarget.Reset();
|
||||||
|
}
|
||||||
|
@ -21,6 +21,11 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
TOptional<float> PrevArmLength;
|
TOptional<float> PrevArmLength;
|
||||||
|
|
||||||
|
TOptional<FVector> SmoothTargetOffsetTarget;
|
||||||
|
float SmoothTargetOffsetSpeed;
|
||||||
|
TOptional<FVector> SmoothSocketOffsetTarget;
|
||||||
|
float SmoothSocketOffsetSpeed;
|
||||||
|
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
UPROPERTY(Transient, EditAnywhere, Category=CameraCollision)
|
UPROPERTY(Transient, EditAnywhere, Category=CameraCollision)
|
||||||
bool bVisualLogCameraCollision = false;
|
bool bVisualLogCameraCollision = false;
|
||||||
@ -29,10 +34,28 @@ protected:
|
|||||||
public:
|
public:
|
||||||
UStevesSpringArmComponent();
|
UStevesSpringArmComponent();
|
||||||
|
|
||||||
|
/// Smoothly change the target offset, instead of jumping
|
||||||
|
UFUNCTION(BlueprintCallable, Category="SpringArm")
|
||||||
|
void SetTargetOffsetSmooth(const FVector& NewTargetOffset, float Speed = 5);
|
||||||
|
/// Interrupt a smooth target offset change, freeze where we are
|
||||||
|
UFUNCTION(BlueprintCallable, Category="SpringArm")
|
||||||
|
void CancelTargetOffsetSmooth();
|
||||||
|
|
||||||
|
/// Smoothly change the socket offset, instead of jumping
|
||||||
|
UFUNCTION(BlueprintCallable, Category="SpringArm")
|
||||||
|
void SetSocketOffsetSmooth(const FVector& NewSocketOffset, float Speed = 5);
|
||||||
|
/// Interrupt a smooth socket offset change, freeze where we are
|
||||||
|
UFUNCTION(BlueprintCallable, Category="SpringArm")
|
||||||
|
void CancelSocketOffsetSmooth();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual FVector BlendLocations(const FVector& DesiredArmLocation,
|
virtual void UpdateDesiredArmLocation(bool bDoTrace,
|
||||||
const FVector& TraceHitLocation,
|
bool bDoLocationLag,
|
||||||
bool bHitSomething,
|
bool bDoRotationLag,
|
||||||
float DeltaTime) override;
|
float DeltaTime) override;
|
||||||
|
virtual FVector BlendLocations(const FVector& DesiredArmLocation,
|
||||||
|
const FVector& TraceHitLocation,
|
||||||
|
bool bHitSomething,
|
||||||
|
float DeltaTime) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user