CharacterController QML Type
Controls the motion of a character. More...
| Import Statement: | import QtQuick3D.Physics |
| Since: | Qt 6.4 |
| Inherits: |
Properties
- collisions : Collisions
- enableShapeHitCallback : bool
(since 6.6) - gravity : vector3d
- gravityOrientation : quaternion
(since 6.13) - maximumStepHeight : real
(since 6.13) - midAirControl : bool
- movement : vector3d
- movementMode : enumeration
(since 6.13) - slideOnSteepSlopes : bool
(since 6.13) - sliding : bool
(since 6.13) - slopeLimit : real
(since 6.13)
Signals
- landed(real speed)
(since 6.13) - shapeHit(PhysicsNode *body, vector3D position, vector3D impulse, vector3D normal)
(since 6.6)
Methods
- void teleport(vector3d position)
Detailed Description
The CharacterController type controls the motion of a character.
A character is an entity that moves under external control, but is still constrained by physical barriers and (optionally) subject to gravity. This is in contrast to dynamic rigid bodies which are either completely controlled by the physics simulation (for non-kinematic bodies); or move exactly where placed, regardless of barriers (for kinematic objects).
To control the motion of a character controller, set movement to the desired velocity.
For a first-person view, the camera is typically placed inside a character controller.
Note: collisionShapes must be set to a single CapsuleShape. No other shapes are supported.
See also Qt Quick 3D Physics Shapes, Bodies and Joints.
Property Documentation
collisions : Collisions [read-only]
This property holds the current collision state of the character. It is either None for no collision, or an OR combination of Side, Up, and Down:
| Constant | Description |
|---|---|
CharacterController.None | The character is not touching anything. If gravity is non-null, this means that the character is in free fall. |
CharacterController.Side | The character is touching something on its side. |
CharacterController.Up | The character is touching something above it. |
CharacterController.Down | The character is touching something below it. In standard gravity, this means that the character is on the ground. |
The directions are relative to the character's up direction, which is opposite to its gravity: gravity plus the gravity of any GravityField acting on it. If that gravity is zero, the last up direction is kept.
enableShapeHitCallback : bool [since 6.6]
This property enables/disables the CharacterController::shapeHit callback for this character controller.
Default value: false
This property was introduced in Qt 6.6.
gravity : vector3d
This property defines the gravitational acceleration that applies to the character. For a character that walks on the ground, it should typically be set to PhysicsWorld.gravity. A floating character that has movement controls in three dimensions will normally have gravity (0, 0, 0).
A GravityField adds its own gravity to this one: one without collision shapes wherever the character is, and one with collision shapes for as long as the character is inside them. A character that is to keep to its own gravity while everything else falls, for instance one swimming or climbing a ladder, is kept out of a field with filterGroup and filterIgnoreGroups.
Setting this property to zero stops the character falling at once, which is how a character grabs a ladder or enters water. Leaving a field's shapes does not: the character keeps the speed it built up under the field's gravity, with movement applying as usual, until it lands on something.
Note: The character's up direction, used for collisions, slopes, steps and gravityOrientation, is opposite to this gravity plus the gravity of any GravityField acting on it.
Default value: (0, 0, 0).
gravityOrientation : quaternion [since 6.13]
This property holds the rotation that turns the scene's up axis, positive y, into the character's current up direction, which is opposite to its gravity. Use it when the direction of gravity changes, such as on a planet, to keep the character upright on the surface.
The rotation follows changes in the direction of gravity a small step at a time, rather than being calculated from a fixed reference direction. This keeps it free of sudden spins anywhere on a sphere, including at its poles. As a result, the rotation depends on the path the character took, not only on where it is.
If the gravity is zero, the rotation keeps its last value.
Combine it with the player's look direction to rotate the character:
CharacterController {
id: playerController
property real playerYaw: 0
rotation: playerController.gravityOrientation
.times(Quaternion.fromEulerAngles(0, playerYaw, 0))
}This property was introduced in Qt 6.13.
See also gravity.
maximumStepHeight : real [default: -1, since 6.13]
This property defines the maximum height step that the character controller can automatically climb over when moving on a surface.
A value of 0 disables stepping. A negative value, which is the default, makes the controller pick a step height from the size of its capsule.
The step height picked for a negative value is currently a quarter of the capsule's height, but this may change in future versions. To keep a fixed relation to the capsule, bind the property to it instead:
CharacterController {
maximumStepHeight: capsule.height * 0.25
collisionShapes: CapsuleShape { id: capsule }
}Note: When using a CapsuleShape, the rounded bottom of the capsule interacts with sharp step edges as if they were inclined surfaces. As a result, the controller may scale steps higher than the defined maximumStepHeight if the step height is smaller than the bottom sphere radius of the capsule and the surface angle does not exceed slopeLimit.
This property was introduced in Qt 6.13.
See also slopeLimit.
midAirControl : bool
This property defines whether the movement property has effect when the character is in free fall. The character is in free fall while its own gravity or a GravityField is pulling on it, or while it is still moving at the speed it built up under a field whose shapes it has left. A value of true means that the character will change direction in mid-air when movement changes. A value of false means that the character will continue on its current trajectory until it hits another object.
Default value: true
movement : vector3d
This property defines the controlled motion of the character. This is the velocity the character would move in the absence of gravity and without interacting with other physics objects.
This property does not reflect the actual velocity of the character. If the character is stuck against terrain, the character can move slower than the speed defined by movement. Conversely, if the character is in free fall, it may move much faster.
Default value: (0, 0, 0)
movementMode : enumeration [default: CharacterController.ForwardBased, since 6.13]
This property defines how the character controller uses the movement vector.
| Constant | Description |
|---|---|
CharacterController.ForwardBased | The character moves relative to its own orientation. Gravity is applied if defined, and landed is emitted. |
CharacterController.Free | The character uses the movement vector as a global movement vector in the scene. In this mode, gravity, midAirControl, and landed are ignored, though gravity is still used to determine the up direction of the node. |
This property was introduced in Qt 6.13.
See also gravity, movement, midAirControl, and landed.
slideOnSteepSlopes : bool [default: false, since 6.13]
This property defines whether the character slides down slopes steeper than slopeLimit. The character can never climb such a slope; with this property false, it stays where it is on one, and with true, it slides down, and sliding is true while it does.
This property was introduced in Qt 6.13.
See also slopeLimit and sliding.
sliding : bool [since 6.13]
This read-only property is true while the character is on a slope steeper than slopeLimit and slideOnSteepSlopes is true, so that the character slides down instead of following its movement. It is always false when slideOnSteepSlopes is false.
Use it to tell the character's animations and input handling that the movement is being limited by the surface.
This property was introduced in Qt 6.13.
See also slopeLimit and slideOnSteepSlopes.
slopeLimit : real [default: 45, since 6.13]
This property defines the steepest slope, as an angle in degrees, that the character controller can climb. The angle is measured from the plane perpendicular to the character's up direction, so 0 only allows flat ground and 90 allows any slope.
Range: [0.0, 90.0]
Note: The slope limit only applies to slopes on static bodies, such as a StaticRigidBody, and not to SphereShape or CapsuleShape shapes. On a dynamic or kinematic body, or on a sphere or capsule, it has no effect, and neither has slideOnSteepSlopes.
This property was introduced in Qt 6.13.
See also maximumStepHeight, slideOnSteepSlopes, and sliding.
Signal Documentation
[since 6.13] landed(real speed)
This signal is emitted when the character lands after being in the air. The speed parameter is how fast, in scene units per second, the character was falling at the moment of impact. It is always positive.
Note: This signal is not emitted when movementMode is CharacterController.Free. It doesn't need enableShapeHitCallback.
Note: The corresponding handler is onLanded.
This signal was introduced in Qt 6.13.
[since 6.6] shapeHit(PhysicsNode *body, vector3D position, vector3D impulse, vector3D normal)
This signal is emitted when movement has been called and it would result in a collision with a DynamicRigidBody or a StaticRigidBody and enableShapeHitCallback is set to true. The parameters body, position, impulse and normal contain the body, position, impulse force and normal for the contact point.
Note: The corresponding handler is onShapeHit.
This signal was introduced in Qt 6.6.
Method Documentation
void teleport(vector3d position)
Immediately move the character to position without checking for collisions. The caller is responsible for avoiding overlap with static objects.
© 2026 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.