129 if (m_movement == newMovement)
131 m_movement = newMovement;
142 if (m_gravity == newGravity)
144 m_gravity = newGravity;
156 const auto g = m_gravity;
164 auto isGrounded = [
this](){
169 if (m_gravity.
y() < 0) {
177 if (m_gravity.
y() > 0) {
188 if ((m_gravity.
x() != 0 || m_gravity.
z() != 0) && m_collisions &
Collision::Side)
194 bool freeFalling = !isGrounded();
196 if (!m_midAirControl)
199 displacement += m_freeFallVelocity * deltaTime;
200 m_freeFallVelocity +=
g * deltaTime;
202 m_freeFallVelocity = displacement / deltaTime +
g * deltaTime;
207 const QVector3D gravityAcceleration = 0.5 * deltaTime * deltaTime *
g;
208 displacement += gravityAcceleration;
217 return m_midAirControl;
222 if (m_midAirControl == newMidAirControl)
224 m_midAirControl = newMidAirControl;
232 m_freeFallVelocity = {};
252 if (m_collisions == newCollisions)
254 m_collisions = newCollisions;
260 return m_enableShapeHitCallback;
263void QCharacterController::setEnableShapeHitCallback(
bool newEnableShapeHitCallback)
265 if (m_enableShapeHitCallback == newEnableShapeHitCallback)
267 m_enableShapeHitCallback = newEnableShapeHitCallback;
void setMidAirControl(bool newMidAirControl)
Q_INVOKABLE void teleport(const QVector3D &position)
void setCollisions(const Collisions &newCollisions)
QCharacterController()
\qmltype CharacterController \inqmlmodule QtQuick3D.Physics \inherits PhysicsBody
QVector3D getDisplacement(float deltaTime)
void enableShapeHitCallbackChanged()
void midAirControlChanged()
void setMovement(const QVector3D &newMovement)
bool enableShapeHitCallback
bool getTeleport(QVector3D &position)
void setGravity(const QVector3D &newGravity)
QQuaternion sceneRotation
The QVector3D class represents a vector or vertex in 3D space.
QVector3D normalized() const noexcept
Returns the normalized unit vector form of this vector.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept
Returns the dot product of v1 and v2.
constexpr float z() const noexcept
Returns the z coordinate of this point.
Combined button and popup list for selecting options.
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)