diff --git a/interface/resources/avatar/avatar-animation.json b/interface/resources/avatar/avatar-animation.json index 1cf4663b1b..738d25e8ee 100644 --- a/interface/resources/avatar/avatar-animation.json +++ b/interface/resources/avatar/avatar-animation.json @@ -4598,6 +4598,10 @@ { "state": "strafeLeftHmd", "var": "isMovingLeftHmd" + }, + { + "state": "idle", + "var": "isNotSeated" } ] }, diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 4d1c20010c..5311d41d76 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -4374,8 +4374,15 @@ float MyAvatar::getRawDriveKey(DriveKeys key) const { } void MyAvatar::relayDriveKeysToCharacterController() { - if (getDriveKey(TRANSLATE_Y) > 0.0f && (!qApp->isHMDMode() || (useAdvancedMovementControls() && getFlyingHMDPref()))) { - _characterController.jump(); + if (_endSitKeyPressComplete) { + if (getDriveKey(TRANSLATE_Y) > 0.0f && (!qApp->isHMDMode() || (useAdvancedMovementControls() && getFlyingHMDPref()))) { + _characterController.jump(); + } + } else { + // used to prevent character from jumping after endSit is called. + if (getDriveKey(TRANSLATE_Y) == 0.0f) { + _endSitKeyPressComplete = true; + } } } @@ -6255,15 +6262,17 @@ void MyAvatar::beginSit(const glm::vec3& position, const glm::quat& rotation) { return; } - _characterController.setSeated(true); - setCollisionsEnabled(false); - setHMDLeanRecenterEnabled(false); - // Disable movement - setSitDriveKeysStatus(false); - centerBody(); - int hipIndex = getJointIndex("Hips"); - clearPinOnJoint(hipIndex); - pinJoint(hipIndex, position, rotation); + if (!_characterController.getSeated()) { + _characterController.setSeated(true); + setCollisionsEnabled(false); + setHMDLeanRecenterEnabled(false); + // Disable movement + setSitDriveKeysStatus(false); + centerBody(); + int hipIndex = getJointIndex("Hips"); + clearPinOnJoint(hipIndex); + pinJoint(hipIndex, position, rotation); + } } void MyAvatar::endSit(const glm::vec3& position, const glm::quat& rotation) { @@ -6281,12 +6290,9 @@ void MyAvatar::endSit(const glm::vec3& position, const glm::quat& rotation) { slamPosition(position); setWorldOrientation(rotation); - // the jump key is used to exit the chair. We add a delay here to prevent - // the avatar from jumping right as they exit the chair. - float TIME_BEFORE_DRIVE_ENABLED_MS = 150.0f; - QTimer::singleShot(TIME_BEFORE_DRIVE_ENABLED_MS, [this]() { - // Enable movement again - setSitDriveKeysStatus(true); - }); + // used to prevent character from jumping after endSit is called. + _endSitKeyPressComplete = false; + + setSitDriveKeysStatus(true); } } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 0108fb5eda..a6cc315631 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -2903,6 +2903,9 @@ private: int _reactionEnabledRefCounts[NUM_AVATAR_BEGIN_END_REACTIONS] { 0, 0, 0 }; mutable std::mutex _reactionLock; + + // used to prevent character from jumping after endSit is called. + bool _endSitKeyPressComplete { false }; }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);