diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index d3fc42cdf2..0b69544527 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -260,6 +260,11 @@ QByteArray MyAvatar::toByteArrayStateful(AvatarDataDetail dataDetail) { return AvatarData::toByteArrayStateful(dataDetail); } +void MyAvatar::resetSensorsAndBody() { + qApp->getActiveDisplayPlugin()->resetSensors(); + reset(true, false, true); +} + void MyAvatar::centerBody() { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "centerBody"); @@ -2481,7 +2486,6 @@ bool MyAvatar::pinJoint(int index, const glm::vec3& position, const glm::quat& o qWarning() << "Pinning is only supported for the hips joint at the moment."; return false; } - qApp->getActiveDisplayPlugin()->resetSensors(); auto jointTranslation = getAbsoluteJointTranslationInObjectFrame(index); auto jointRotation = getAbsoluteJointRotationInObjectFrame(index); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index edba2929e8..3cc665b533 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -99,6 +99,7 @@ public: void reset(bool andRecenter = false, bool andReload = true, bool andHead = true); + Q_INVOKABLE void resetSensorsAndBody(); Q_INVOKABLE void centerBody(); // thread-safe Q_INVOKABLE void clearIKJointLimitHistory(); // thread-safe diff --git a/scripts/tutorials/entity_scripts/sit.js b/scripts/tutorials/entity_scripts/sit.js index 56d1ab2928..5c010c1906 100644 --- a/scripts/tutorials/entity_scripts/sit.js +++ b/scripts/tutorials/entity_scripts/sit.js @@ -12,6 +12,7 @@ var MAX_IK_ERROR = 20; var DESKTOP_UI_CHECK_INTERVAL = 250; var DESKTOP_MAX_DISTANCE = 5; + var SIT_DELAY = 20 this.entityID = null; this.timers = {}; @@ -48,40 +49,47 @@ return; } - MyAvatar.overrideRoleAnimation(ROLE, ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME); - MyAvatar.setParentID(this.entityID); - MyAvatar.characterControllerEnabled = false; - MyAvatar.hmdLeanRecenterEnabled = false; + MyAvatar.resetSensors(); - var properties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); - var index = MyAvatar.getJointIndex("Hips"); - MyAvatar.pinJoint(index, properties.position, properties.rotation); + var that = this; + Script.setTimeout(function() { + MyAvatar.setParentID(that.entityID); + MyAvatar.characterControllerEnabled = false; + MyAvatar.hmdLeanRecenterEnabled = false; + MyAvatar.overrideRoleAnimation(ROLE, ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME); - this.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(props) { - return { headType: 0 }; - }, ["headType"]); + var properties = Entities.getEntityProperties(that.entityID, ["position", "rotation"]); + var index = MyAvatar.getJointIndex("Hips"); + MyAvatar.pinJoint(index, properties.position, properties.rotation); - Script.update.connect(this, this.update); - Controller.keyPressEvent.connect(this, this.keyPressed); - Controller.keyReleaseEvent.connect(this, this.keyReleased); - for (var i in RELEASE_KEYS) { - Controller.captureKeyEvents({ text: RELEASE_KEYS[i] }); - } + that.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(props) { + return { headType: 0 }; + }, ["headType"]); + + Script.update.connect(that, that.update); + Controller.keyPressEvent.connect(that, that.keyPressed); + Controller.keyReleaseEvent.connect(that, that.keyReleased); + for (var i in RELEASE_KEYS) { + Controller.captureKeyEvents({ text: RELEASE_KEYS[i] }); + } + }, SIT_DELAY); } this.sitUp = function() { + MyAvatar.bodyPitch = 0.0; + MyAvatar.bodyRoll = 0.0; + MyAvatar.restoreRoleAnimation(ROLE); - MyAvatar.setParentID(""); MyAvatar.characterControllerEnabled = true; MyAvatar.hmdLeanRecenterEnabled = true; + MyAvatar.setParentID(""); var index = MyAvatar.getJointIndex("Hips"); MyAvatar.clearPinOnJoint(index); MyAvatar.removeAnimationStateHandler(this.animStateHandlerID); - MyAvatar.bodyPitch = 0.0; - MyAvatar.bodyRoll = 0.0; + MyAvatar.resetSensors(); Script.update.disconnect(this, this.update); Controller.keyPressEvent.disconnect(this, this.keyPressed);