Configure character mesh transform defaults

This commit is contained in:
2026-04-26 16:20:29 +08:00
parent d9faa65a27
commit 4d2186c43c
3 changed files with 25 additions and 0 deletions

View File

@@ -32,6 +32,13 @@ APHYCharacterBase::APHYCharacterBase(const FObjectInitializer& ObjectInitializer
{
bReplicates = true;
const UPHYCharacterSettings* CharacterSettings = GetDefault<UPHYCharacterSettings>();
if (USkeletalMeshComponent* SourceMeshComponent = GetMesh())
{
SourceMeshComponent->SetRelativeLocation(CharacterSettings ? CharacterSettings->DefaultMeshRelativeLocation : FVector(0.0f, 0.0f, -90.0f));
SourceMeshComponent->SetRelativeRotation(CharacterSettings ? CharacterSettings->DefaultMeshRelativeRotation : FRotator(0.0f, -90.0f, 0.0f));
}
CharacterStateComponent = CreateDefaultSubobject<UPHYCharacterStateComponent>(TEXT("CharacterStateComponent"));
CombatSystemComponent = CreateDefaultSubobject<UGCS_CombatSystemComponent>(TEXT("CombatSystemComponent"));
TargetingSystemComponent = CreateDefaultSubobject<UGCS_TargetingSystemComponent>(TEXT("TargetingSystemComponent"));
@@ -80,6 +87,8 @@ APHYCharacterBase::APHYCharacterBase(const FObjectInitializer& ObjectInitializer
DisplayMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("DisplayMeshComponent"));
DisplayMeshComponent->SetupAttachment(GetMesh());
DisplayMeshComponent->SetRelativeLocation(FVector::ZeroVector);
DisplayMeshComponent->SetRelativeRotation(FRotator::ZeroRotator);
DisplayMeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
DisplayMeshComponent->SetGenerateOverlapEvents(false);
}
@@ -618,6 +627,12 @@ void APHYCharacterBase::ApplyCharacterSettings()
MoveComponent->MaxAcceleration = Settings->DefaultMaxAcceleration;
}
if (USkeletalMeshComponent* SourceMeshComponent = GetMesh())
{
SourceMeshComponent->SetRelativeLocation(Settings->DefaultMeshRelativeLocation);
SourceMeshComponent->SetRelativeRotation(Settings->DefaultMeshRelativeRotation);
}
if (CharacterStateComponent && GetCharacterMovement() && GetCharacterMovement()->IsFalling())
{
CharacterStateComponent->SetMovementState(PHYGameplayTags::State_Movement_Falling);

View File

@@ -45,6 +45,14 @@ public:
UPROPERTY(Config, EditDefaultsOnly, Category="PHY|Character")
float DefaultMaxAcceleration = 2048.0f;
/** @brief 角色源 Mesh 相对 Capsule 的默认位置。 */
UPROPERTY(Config, EditDefaultsOnly, Category="PHY|Character|Mesh")
FVector DefaultMeshRelativeLocation = FVector(0.0f, 0.0f, -90.0f);
/** @brief 角色源 Mesh 相对 Capsule 的默认旋转。 */
UPROPERTY(Config, EditDefaultsOnly, Category="PHY|Character|Mesh")
FRotator DefaultMeshRelativeRotation = FRotator(0.0f, -90.0f, 0.0f);
/** @brief 默认交互选项索引。 */
UPROPERTY(Config, EditDefaultsOnly, Category="PHY|Character")
int32 DefaultInteractionOption = 0;