-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Source/Cloud9/Character/Components/Cloud9SpringArmComponent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "Cloud9SpringArmComponent.h" | ||
|
||
|
||
UCloud9SpringArmComponent::UCloud9SpringArmComponent() | ||
{ | ||
RotationVerticalLagSpeed = 0.0f; | ||
} | ||
|
||
void UCloud9SpringArmComponent::OnRegister() | ||
{ | ||
Super::OnRegister(); | ||
TargetRelativeRotation = RelativeSocketRotation.Rotator(); | ||
} | ||
|
||
void UCloud9SpringArmComponent::TickComponent( | ||
float DeltaTime, | ||
ELevelTick TickType, | ||
FActorComponentTickFunction* ThisTickFunction) | ||
{ | ||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); | ||
|
||
auto NewRotation = TargetRelativeRotation; | ||
if (RotationVerticalLagSpeed != 0.0f) | ||
{ | ||
const auto OldRotation = RelativeSocketRotation.Rotator(); | ||
NewRotation = FMath::Lerp( | ||
OldRotation, | ||
TargetRelativeRotation, | ||
DeltaTime / RotationVerticalLagSpeed * RotationScale); | ||
} | ||
|
||
RelativeSocketRotation = NewRotation.Quaternion(); | ||
|
||
UpdateChildTransforms(); | ||
} |
36 changes: 36 additions & 0 deletions
36
Source/Cloud9/Character/Components/Cloud9SpringArmComponent.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Cloud9CharacterComponent.h" | ||
#include "GameFramework/SpringArmComponent.h" | ||
#include "Cloud9SpringArmComponent.generated.h" | ||
|
||
|
||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) | ||
class CLOUD9_API UCloud9SpringArmComponent | ||
: public USpringArmComponent | ||
, public ICloud9CharacterComponent | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
UCloud9SpringArmComponent(); | ||
|
||
virtual void TickComponent( | ||
float DeltaTime, | ||
ELevelTick TickType, | ||
FActorComponentTickFunction* ThisTickFunction | ||
) override; | ||
|
||
virtual void OnRegister() override; | ||
|
||
private: | ||
static constexpr float RotationScale = 360.0f; | ||
|
||
/** Vertical rotation speed lag for camera*/ | ||
UPROPERTY(EditDefaultsOnly, Category=Lag, | ||
meta=(ClampMin="0.0", ClampMax="10000.0", UIMin = "0.0", UIMax = "10000.0")) | ||
float RotationVerticalLagSpeed; | ||
|
||
FRotator TargetRelativeRotation; | ||
}; |