为什么 PlayerController "own" 偏航俯仰和滚动,而 Character "owns" 它的位置?

Why does PlayerController "own" the yaw pitch and roll, but the Character "owns" its location?

我是 UE4 的新手,正在尝试了解有关控制角色 pawn 的一些基本概念。我正在摸索着尝试实现一些角色移动逻辑。我打算使用基本的 WASD 来向前、向后、左右移动角色——就像几乎每个基本的第一人称射击游戏一样。我还想要鼠标输入来旋转角色。

我有自己的习惯 PlayerControllerCharacter classes.

添加代码来移动角色 - 前面、后面、侧面 - 似乎都在角色 class 本身中。那里有一个名为 AddMovementInput 的方法,它似乎可以为我修改位置。这也让我想到了class这个字符"owns"它自己的位置。这是有道理的,因为一次可能有多个字符 class,每个字符在不同的位置,对吗?

添加旋转角色的代码,控制旋转的方法类似-AddControllerYawInputAddControllerPitchInputAddControllerRollInput。简单地查看函数的名称表明偏航俯仰和滚动是由播放器控制器 "owned"。查看函数的文档和评论进一步支持了这一点:"Add input (affecting Yaw) to the Controller's ControlRotation, if it is a local PlayerController." 所以在我看来,偏航俯仰和滚动是值 "owned"通过播放器控制器,对吗?

作为初学者,这让我感到困惑:我对位置存储在角色本身但旋转似乎没有这一事实感到困惑。

我有兴趣了解我应该如何 "think about" 角色或棋子移动。我只是不清楚,这让我对这个话题挂断了。

此设计背后的意图是将控制机制角色物理分开。在编写软件方面,的想法是 decouple 玩家控制 game-world 物理中角色旋转的游戏交互机制。例如,我可以瞄准向上,而我的角色body不知何故倾斜向下 -- 因此可能会与位于其下方的 object 发生物理碰撞。

看,您对“谁 拥有 什么”的观察是正确的。 You can see AController, base class of PlayerController, 有一个类型为 [=13= 的成员变量 ControlRotation ].该数据成员的文档说:

ControlRotation (accessed via GetControlRotation() ), determines the viewing/aiming direction of the controlled Pawn ...

GetControlRotation() further clarifies:

This is the full aim rotation, which [...] may differ from the rotation of the controlled Pawn (which may choose not to visually pitch or roll, for example).

例如,控制器旋转与角色为自己管理的任何“旋转相关”分开。

这在文档中得到进一步支持,例如参见 [​​=15=](base class of ACharacter):

Pawn is the base class of all actors that can be possessed by players or AI. They are the physical representations of players and creatures in a level.

AController以下:

Controllers are non-physical actors that can possess a Pawn to control its actions.