CharacterController QML Type
控制字符的运动。更多
Import Statement: | import QtQuick3D.Physics |
Since: | Qt 6.4 |
Inherits: |
属性
- collisions : Collisions
- enableShapeHitCallback : bool
(since 6.6)
- gravity : vector3d
- midAirControl : bool
- movement : vector3d
信号
- shapeHit(PhysicsNode *body, vector3D position, vector3D impulse, vector3D normal)
(since 6.6)
方法
- teleport(vector3d position)
详细说明
CharacterController 类型控制角色的运动。
角色是在外部控制下移动的实体,但仍受物理障碍物的限制,并(可选择)受重力影响。这与dynamic rigid bodies 不同,后者要么完全由物理模拟控制(对于非运动体),要么不受障碍物影响(对于运动物体),完全按照放置的位置移动。
要控制角色控制器的运动,可将movement 设置为所需的速度。
对于第一人称视角,摄像机通常放置在角色控制器内。
注意: collisionShapes 必须设置为单个CapsuleShape 。不支持其他形状。
注: 角色控制器可以缩放低于胶囊形状高度四分之一的障碍物。
另请参阅 形状和主体概述文档。
属性文档
collisions : Collisions |
该属性用于保存角色当前的碰撞状态。它要么是None
表示无碰撞,要么是Side
、Up
和Down
的 OR 组合:
常量 | 说明 |
---|---|
CharacterController.None | 角色未接触任何物体。如果重力不为零,则表示角色处于自由落体状态。 |
CharacterController.Side | 字符正接触其侧面的某物。 |
CharacterController.Up | 角色正在接触上方的物体。 |
CharacterController.Down | 角色正在接触下方的物体。在标准重力情况下,这意味着角色处于落地状态。 |
注: 方向是相对于标准重力定义的:无论CharacterController.gravity 或Up
的值是多少,它始终沿着 Y 轴正向运行。PhysicsWorld.gravity
enableShapeHitCallback : bool |
gravity : vector3d |
该属性定义了适用于角色的重力加速度。对于在地面上行走的角色,通常应将其设置为PhysicsWorld.gravity 。在三维空间中具有移动控制功能的浮动角色,其重力加速度通常为(0, 0, 0)
。
默认值:(0, 0, 0)
。
midAirControl : bool |
movement : vector3d |
该属性定义了角色的受控运动。这是在没有重力且不与其他物理对象相互作用的情况下,角色的运动速度。
该属性并不反映角色的实际速度。如果角色被地形卡住,其移动速度会低于movement
所定义的速度。相反,如果角色处于自由落体状态,其移动速度可能会快很多。
默认值:(0, 0, 0)
信号 文档
|
当调用movement 并导致与DynamicRigidBody 或StaticRigidBody 发生碰撞,且enableShapeHitCallback 设置为true
时,将发出该信号。参数body,position,impulse 和normal 包含接触点的主体、位置、冲力和法线。
注: 相应的处理程序是onShapeHit
。
该信号在 Qt 6.6 中引入。
方法文档
teleport(vector3d position) |
在不检查碰撞的情况下立即将字符移动到position 。调用者有责任避免与静态对象重叠。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.