Smoothly rotate the mesh in the direction they are moving
This commit is contained in:
parent
5289b0c765
commit
70f474c5ee
BIN
Content/Enemy/DA_Enemy.uasset
(Stored with Git LFS)
BIN
Content/Enemy/DA_Enemy.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Player/BP_PlayerCharacter.uasset
(Stored with Git LFS)
BIN
Content/Player/BP_PlayerCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
@ -61,7 +61,7 @@ void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enem
|
||||
if (enemyDataAsset != nullptr)
|
||||
{
|
||||
// TODO: Load more data
|
||||
PaperFlipbookComponent->SetFlipbook(enemyDataAsset->PaperFlipbook);
|
||||
StaticMeshComponent->SetStaticMesh(enemyDataAsset->StaticMesh);
|
||||
|
||||
BehaviorTree = enemyDataAsset->BehaviorTree;
|
||||
}
|
||||
@ -70,7 +70,7 @@ void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enem
|
||||
void AEnemyCharacter::ResetData_Implementation()
|
||||
{
|
||||
// TODO: Reset more data
|
||||
PaperFlipbookComponent->SetFlipbook(nullptr);
|
||||
StaticMeshComponent->SetStaticMesh(nullptr);
|
||||
|
||||
BehaviorTree = nullptr;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class VAMPIRES_API UEnemyDataAsset : public UDataAsset
|
||||
|
||||
public:
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
UPaperFlipbook* PaperFlipbook;
|
||||
UStaticMesh* StaticMesh;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||
UBehaviorTree* BehaviorTree = nullptr;
|
||||
|
@ -16,10 +16,8 @@ AVampireCharacter::AVampireCharacter()
|
||||
// Create Health Component
|
||||
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
|
||||
|
||||
PaperFlipbookComponent = CreateDefaultSubobject<UPaperFlipbookComponent>(TEXT("Paper Flipbook Component"));
|
||||
PaperFlipbookComponent->SetRelativeRotation(FRotator(0.0f, 90.0f,-90.0f));
|
||||
PaperFlipbookComponent->SetRelativeScale3D(FVector(0.2f, 0.2f, 0.2f));
|
||||
PaperFlipbookComponent->SetupAttachment(RootComponent);
|
||||
StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh Component"));
|
||||
StaticMeshComponent->SetupAttachment(RootComponent);
|
||||
|
||||
//Create Weapon Inventory Component
|
||||
WeaponInventoryComponent = CreateDefaultSubobject<UWeaponInventoryComponent>(TEXT("Weapon Inventory Component"));
|
||||
@ -29,6 +27,7 @@ AVampireCharacter::AVampireCharacter()
|
||||
void AVampireCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -37,6 +36,11 @@ void AVampireCharacter::Tick(float 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)
|
||||
|
@ -20,9 +20,12 @@ class VAMPIRES_API AVampireCharacter : public ACharacter, public IInputable
|
||||
|
||||
public:
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
UPaperFlipbookComponent* PaperFlipbookComponent;
|
||||
UStaticMeshComponent* StaticMeshComponent;
|
||||
|
||||
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
float SlerpSpeed = 10.0f;
|
||||
protected:
|
||||
UPROPERTY()
|
||||
UHealthComponent* HealthComponent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user