134 if (m_movement == newMovement)
136 m_movement = newMovement;
147 if (m_gravity == newGravity)
149 m_gravity = newGravity;
161 const auto g = m_gravity;
169 auto isGrounded = [
this](){
174 if (m_gravity.
y() < 0) {
182 if (m_gravity.
y() > 0) {
193 if ((m_gravity.
x() != 0 || m_gravity.
z() != 0) && m_collisions &
Collision::Side)
199 bool freeFalling = !isGrounded();
201 if (!m_midAirControl)
204 displacement += m_freeFallVelocity * deltaTime;
205 m_freeFallVelocity +=
g * deltaTime;
207 m_freeFallVelocity = displacement / deltaTime +
g * deltaTime;
212 const QVector3D gravityAcceleration = 0.5 * deltaTime * deltaTime *
g;
213 displacement += gravityAcceleration;
222 return m_midAirControl;
227 if (m_midAirControl == newMidAirControl)
229 m_midAirControl = newMidAirControl;
237 m_freeFallVelocity = {};
257 if (m_collisions == newCollisions)
259 m_collisions = newCollisions;
265 return m_enableShapeHitCallback;
273void QCharacterController::setEnableShapeHitCallback(
bool newEnableShapeHitCallback)
275 if (m_enableShapeHitCallback == newEnableShapeHitCallback)
277 m_enableShapeHitCallback = newEnableShapeHitCallback;
void setMidAirControl(bool newMidAirControl)
Q_INVOKABLE void teleport(const QVector3D &position)
QAbstractPhysXNode * createPhysXBackend() final
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)