Files
ChildHood/Source/ChildHood/ChildHoodPlayerController.cpp
T
starmen1265 3c69445d90 feat(player-controller): 实现v0.1角色控制系统
- 移除跳跃逻辑:删除JumpAction、DoJumpStart/End
- 调整CMC参数:MaxWalkSpeed=450, Acceleration=2250, Brake=1500, RotationRate=720
- 调整SpringArm:TargetArmLength=350, SocketOffset.Z=80, CameraLag=6, ProbeSize=12
- 添加Pitch限幅:ViewPitchMin=-30, ViewPitchMax=45, 初始俯角-15°
- 新增交互状态:bIsInteracting + SetInteracting/IsInteracting/IsRunning
- 新增交互IA:InteractAction/CancelAction/SwitchInteractAction(占位回调)
- DoMove添加交互中忽略移动输入检查

Task: P-011
2026-06-10 17:39:37 +08:00

81 lines
2.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "ChildHoodPlayerController.h"
#include "EnhancedInputSubsystems.h"
#include "Engine/LocalPlayer.h"
#include "InputMappingContext.h"
#include "Blueprint/UserWidget.h"
#include "ChildHood.h"
#include "Widgets/Input/SVirtualJoystick.h"
void AChildHoodPlayerController::BeginPlay()
{
Super::BeginPlay();
// C3: 设置摄像机俯仰角限制(垂直旋转 +45°/-30°)
if (PlayerCameraManager)
{
PlayerCameraManager->ViewPitchMin = -30.0f; // 向下看最多 30°
PlayerCameraManager->ViewPitchMax = 45.0f; // 向上看最多 45°
}
// C1: 初始俯角 -15°(摄像机默认略向下看向角色)
if (GetControlRotation().Pitch == 0.f)
{
SetControlRotation(FRotator(-15.0f, GetControlRotation().Yaw, GetControlRotation().Roll));
}
// only spawn touch controls on local player controllers
if (ShouldUseTouchControls() && IsLocalPlayerController())
{
// spawn the mobile controls widget
MobileControlsWidget = CreateWidget<UUserWidget>(this, MobileControlsWidgetClass);
if (MobileControlsWidget)
{
// add the controls to the player screen
MobileControlsWidget->AddToPlayerScreen(0);
} else {
UE_LOG(LogChildHood, Error, TEXT("Could not spawn mobile controls widget."));
}
}
}
void AChildHoodPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
// only add IMCs for local player controllers
if (IsLocalPlayerController())
{
// Add Input Mapping Contexts
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
{
for (UInputMappingContext* CurrentContext : DefaultMappingContexts)
{
Subsystem->AddMappingContext(CurrentContext, 0);
}
// only add these IMCs if we're not using mobile touch input
if (!ShouldUseTouchControls())
{
for (UInputMappingContext* CurrentContext : MobileExcludedMappingContexts)
{
Subsystem->AddMappingContext(CurrentContext, 0);
}
}
}
}
}
bool AChildHoodPlayerController::ShouldUseTouchControls() const
{
// are we on a mobile platform? Should we force touch?
return SVirtualJoystick::ShouldDisplayTouchInterface() || bForceTouchControls;
}