Section 8: Advanced Movement - Lecture 117
Hip Aim Offset
This commit is contained in:
parent
acd849d4fc
commit
56fad37200
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
|
|
||||||
[/Script/EngineSettings.GameMapsSettings]
|
[/Script/EngineSettings.GameMapsSettings]
|
||||||
GameDefaultMap=/Game/ModSciInteriors/Maps/Example_2_Dynamic.Example_2_Dynamic
|
GameDefaultMap=/Game/_Game/Maps/DefaultMap.DefaultMap
|
||||||
EditorStartupMap=/Game/ModSciInteriors/Maps/Example_2_Dynamic.Example_2_Dynamic
|
EditorStartupMap=/Game/_Game/Maps/DefaultMap.DefaultMap
|
||||||
GlobalDefaultGameMode=/Game/_Game/GameMode/ShooterGameModeBaseBP.ShooterGameModeBaseBP_C
|
GlobalDefaultGameMode=/Game/_Game/GameMode/ShooterGameModeBaseBP.ShooterGameModeBaseBP_C
|
||||||
|
|
||||||
[/Script/HardwareTargeting.HardwareTargetingSettings]
|
[/Script/HardwareTargeting.HardwareTargetingSettings]
|
||||||
|
|
BIN
Content/ParagonLtBelica/Characters/Heroes/Belica/Meshes/Belica_Skeleton.uasset (Stored with Git LFS)
BIN
Content/ParagonLtBelica/Characters/Heroes/Belica/Meshes/Belica_Skeleton.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/_Game/Character/Animations/Idle_Turn_90_Left_Trimmed.uasset (Stored with Git LFS)
Normal file
BIN
Content/_Game/Character/Animations/Idle_Turn_90_Left_Trimmed.uasset (Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/_Game/Character/Animations/Idle_Turn_90_Right_Trimmed.uasset (Stored with Git LFS)
Normal file
BIN
Content/_Game/Character/Animations/Idle_Turn_90_Right_Trimmed.uasset (Stored with Git LFS)
Normal file
Binary file not shown.
|
@ -1,3 +0,0 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:ea499b26b1ff7085faf02c40cb4642ecb7c60c09db55a5f7de4d85aea8e4be60
|
|
||||||
size 1199
|
|
|
@ -1,3 +0,0 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:7b8c1a9f82a3ae31625ce118399a72146e4249f1c1b9c8dbdfffc91861ff6682
|
|
||||||
size 1215
|
|
|
@ -1,3 +0,0 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:47ee89e3a2a3584ffc0f9b4b2915c59f0a653ce08699975527a7dddfc6cd1dde
|
|
||||||
size 1223
|
|
BIN
Content/_Game/Character/ShooterAnimBP.uasset (Stored with Git LFS)
BIN
Content/_Game/Character/ShooterAnimBP.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/_Game/Maps/DefaultMap.umap (Stored with Git LFS)
BIN
Content/_Game/Maps/DefaultMap.umap (Stored with Git LFS)
Binary file not shown.
|
@ -7,13 +7,26 @@
|
||||||
#include "GameFramework/CharacterMovementComponent.h"
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
#include "Kismet/KismetMathLibrary.h"
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
|
|
||||||
|
UShooterAnimInstance::UShooterAnimInstance() :
|
||||||
|
Speed(0.f),
|
||||||
|
bIsInAir(false),
|
||||||
|
bIsAccelerating(false),
|
||||||
|
MovementOffsetYaw(0.f),
|
||||||
|
LastMovementOffsetYaw(0.f),
|
||||||
|
bAiming(false),
|
||||||
|
CharacterYaw(0.f),
|
||||||
|
CharacterYawLastFrame(0.f),
|
||||||
|
RootYawOffset(0.f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void UShooterAnimInstance::UpdateAnimationProperties(float DeltaTime)
|
void UShooterAnimInstance::UpdateAnimationProperties(float DeltaTime)
|
||||||
{
|
{
|
||||||
if (ShooterCharacter)
|
if (!ShooterCharacter)
|
||||||
ShooterCharacter = Cast<AShooterCharacter>(TryGetPawnOwner());
|
ShooterCharacter = Cast<AShooterCharacter>(TryGetPawnOwner());
|
||||||
|
|
||||||
if (ShooterCharacter)
|
if (!ShooterCharacter) return;
|
||||||
{
|
|
||||||
// Get the speed of the character from velocity
|
// Get the speed of the character from velocity
|
||||||
FVector Velocity{ ShooterCharacter->GetVelocity() };
|
FVector Velocity{ ShooterCharacter->GetVelocity() };
|
||||||
Velocity.Z = 0;
|
Velocity.Z = 0;
|
||||||
|
@ -36,7 +49,8 @@ void UShooterAnimInstance::UpdateAnimationProperties(float DeltaTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
bAiming = ShooterCharacter->GetAiming();
|
bAiming = ShooterCharacter->GetAiming();
|
||||||
}
|
|
||||||
|
TurnInPlace();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UShooterAnimInstance::NativeInitializeAnimation()
|
void UShooterAnimInstance::NativeInitializeAnimation()
|
||||||
|
@ -45,3 +59,54 @@ void UShooterAnimInstance::NativeInitializeAnimation()
|
||||||
|
|
||||||
ShooterCharacter = Cast<AShooterCharacter>(TryGetPawnOwner());
|
ShooterCharacter = Cast<AShooterCharacter>(TryGetPawnOwner());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UShooterAnimInstance::TurnInPlace()
|
||||||
|
{
|
||||||
|
if (!ShooterCharacter) return;
|
||||||
|
if (Speed > 0)
|
||||||
|
{
|
||||||
|
// Don't want to turn in place; Character is moving
|
||||||
|
RootYawOffset = 0.f;
|
||||||
|
CharacterYaw = ShooterCharacter->GetActorRotation().Yaw;
|
||||||
|
CharacterYawLastFrame = CharacterYaw;
|
||||||
|
RotationCurve = 0.f;
|
||||||
|
RotationCurveLastFrame = 0.f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CharacterYawLastFrame = CharacterYaw;
|
||||||
|
CharacterYaw = ShooterCharacter->GetActorRotation().Yaw;
|
||||||
|
const float YawDelta { CharacterYaw - CharacterYawLastFrame };
|
||||||
|
|
||||||
|
// Root Yaw Offset, updated and clamped to [-180, 180]
|
||||||
|
RootYawOffset = UKismetMathLibrary::NormalizeAxis(RootYawOffset - YawDelta);
|
||||||
|
|
||||||
|
// 1.0 if turning, 0.0 if not
|
||||||
|
const float Turning { GetCurveValue(TEXT("Turning")) };
|
||||||
|
if (Turning)
|
||||||
|
{
|
||||||
|
RotationCurveLastFrame = RotationCurve;
|
||||||
|
RotationCurve = GetCurveValue(TEXT("Rotation"));
|
||||||
|
const float DeltaRotation { RotationCurve = RotationCurveLastFrame };
|
||||||
|
|
||||||
|
// If RootYawOffset > 0, -> Turning Left, If RootYawOffset < 0, -> Turning Right
|
||||||
|
RootYawOffset > 0 ? RootYawOffset -= DeltaRotation : RootYawOffset += DeltaRotation;
|
||||||
|
|
||||||
|
const float ABSRootYawOffset { FMath::Abs(RootYawOffset) };
|
||||||
|
if (ABSRootYawOffset)
|
||||||
|
{
|
||||||
|
const float YawExcess { ABSRootYawOffset - 90.f };
|
||||||
|
RootYawOffset > 0 ? RootYawOffset -= YawExcess : RootYawOffset += YawExcess;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if (GEngine)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(1, -1, FColor::Blue,
|
||||||
|
FString::Printf(TEXT("CharacterYaw: %f"), CharacterYaw));
|
||||||
|
|
||||||
|
GEngine->AddOnScreenDebugMessage(2, -1, FColor::Red,
|
||||||
|
FString::Printf(TEXT("RootYawOffset: %f"), RootYawOffset));
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,11 +17,16 @@ class SHOOTER_API UShooterAnimInstance : public UAnimInstance
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
UShooterAnimInstance();
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void UpdateAnimationProperties(float DeltaTime);
|
void UpdateAnimationProperties(float DeltaTime);
|
||||||
|
|
||||||
virtual void NativeInitializeAnimation() override;
|
virtual void NativeInitializeAnimation() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/** Handle turning in place variables */
|
||||||
|
void TurnInPlace();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = true))
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = true))
|
||||||
|
@ -49,4 +54,19 @@ private:
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = true))
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = true))
|
||||||
bool bAiming;
|
bool bAiming;
|
||||||
|
|
||||||
|
/** Yaw of the character this frame */
|
||||||
|
float CharacterYaw;
|
||||||
|
|
||||||
|
/** Yaw of the character the previous frame */
|
||||||
|
float CharacterYawLastFrame;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Turn In Place", meta = (AllowPrivateAccess = true))
|
||||||
|
float RootYawOffset;
|
||||||
|
|
||||||
|
/** Rotation curve value this frame */
|
||||||
|
float RotationCurve;
|
||||||
|
|
||||||
|
/** Rotation curve value last frame */
|
||||||
|
float RotationCurveLastFrame;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue