Smoothly rotate the mesh in the direction they are moving

This commit is contained in:
baz 2025-02-10 20:36:44 +00:00
parent 5289b0c765
commit 70f474c5ee
6 changed files with 19 additions and 12 deletions

BIN
Content/Enemy/DA_Enemy.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -61,7 +61,7 @@ void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enem
if (enemyDataAsset != nullptr) if (enemyDataAsset != nullptr)
{ {
// TODO: Load more data // TODO: Load more data
PaperFlipbookComponent->SetFlipbook(enemyDataAsset->PaperFlipbook); StaticMeshComponent->SetStaticMesh(enemyDataAsset->StaticMesh);
BehaviorTree = enemyDataAsset->BehaviorTree; BehaviorTree = enemyDataAsset->BehaviorTree;
} }
@ -70,7 +70,7 @@ void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enem
void AEnemyCharacter::ResetData_Implementation() void AEnemyCharacter::ResetData_Implementation()
{ {
// TODO: Reset more data // TODO: Reset more data
PaperFlipbookComponent->SetFlipbook(nullptr); StaticMeshComponent->SetStaticMesh(nullptr);
BehaviorTree = nullptr; BehaviorTree = nullptr;
} }

View File

@ -19,7 +19,7 @@ class VAMPIRES_API UEnemyDataAsset : public UDataAsset
public: public:
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
UPaperFlipbook* PaperFlipbook; UStaticMesh* StaticMesh;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
UBehaviorTree* BehaviorTree = nullptr; UBehaviorTree* BehaviorTree = nullptr;

View File

@ -16,10 +16,8 @@ AVampireCharacter::AVampireCharacter()
// Create Health Component // Create Health Component
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component")); HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
PaperFlipbookComponent = CreateDefaultSubobject<UPaperFlipbookComponent>(TEXT("Paper Flipbook Component")); StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh Component"));
PaperFlipbookComponent->SetRelativeRotation(FRotator(0.0f, 90.0f,-90.0f)); StaticMeshComponent->SetupAttachment(RootComponent);
PaperFlipbookComponent->SetRelativeScale3D(FVector(0.2f, 0.2f, 0.2f));
PaperFlipbookComponent->SetupAttachment(RootComponent);
//Create Weapon Inventory Component //Create Weapon Inventory Component
WeaponInventoryComponent = CreateDefaultSubobject<UWeaponInventoryComponent>(TEXT("Weapon Inventory Component")); WeaponInventoryComponent = CreateDefaultSubobject<UWeaponInventoryComponent>(TEXT("Weapon Inventory Component"));
@ -30,6 +28,7 @@ void AVampireCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
} }
// Called every frame // Called every frame
@ -37,6 +36,11 @@ void AVampireCharacter::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
float newYaw = FMath::Atan2(PreviousMovementDirection.Y, PreviousMovementDirection.X) * 180.0f / PI;
FQuat newRotation = FQuat::Slerp(StaticMeshComponent->GetComponentRotation().Quaternion(),
FRotator(0.0f, newYaw, 0.0f).Quaternion(),
DeltaTime * SlerpSpeed);
StaticMeshComponent->SetRelativeRotation(newRotation);
} }
void AVampireCharacter::Input_Move_Implementation(FVector2D value) void AVampireCharacter::Input_Move_Implementation(FVector2D value)

View File

@ -20,9 +20,12 @@ class VAMPIRES_API AVampireCharacter : public ACharacter, public IInputable
public: public:
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
UPaperFlipbookComponent* PaperFlipbookComponent; UStaticMeshComponent* StaticMeshComponent;
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f); FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
UPROPERTY(BlueprintReadWrite, EditAnywhere)
float SlerpSpeed = 10.0f;
protected: protected:
UPROPERTY() UPROPERTY()
UHealthComponent* HealthComponent; UHealthComponent* HealthComponent;