gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 01:28:31 25 4
gpt4 key购买 nike

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

我有自己的自定义 PlayerControllerCharacter 类。

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

添加旋转角色的代码有类似的控制旋转的方法- AddControllerYawInput, AddControllerPitchInput, AddControllerRollInput。只需查看函数的名称,就会发现偏航俯仰和横滚由玩家 Controller “拥有”。查看函数的文档和评论进一步支持了这一点:“将输入(影响偏航)添加到 Controller 的 ControlRotation,如果它是本地 PlayerController。”所以在我看来, yaw pitch 和 roll 是玩家 Controller “拥有”的值,对吧?

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

我有兴趣了解应该如何“思考”角色或兵的移动。我只是不清楚,这让我在这个话题上挂断了。

最佳答案

此设计背后的意图是将控制机制角色物理分开。在写软件方面,的思路是decouple 玩家控制游戏世界物理中角色旋转的游戏互动机制的旋转。例如,我可以瞄准向上,而我角色的 body 以某种方式倾斜向下——因此可能会与位于其下方的物体发生物理碰撞.

看,您对“谁拥有什么”的看法是正确的。 You can see AControllerPlayerController基类,有一个类型为 FRotator 的成员变量 ControlRotation >。该数据成员的文档说:

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

GetControlRotation() further clarifies :

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

与此类似, Controller 旋转与角色自行管理的任何“旋转相关”保持分离。

这在文档中得到了进一步的支持,例如参见Pawn(ACharacter基类):

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

AController下:

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

关于c++ - 为什么 PlayerController "own"是偏航俯仰和滚动,而 Character "owns"是它的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52013550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com