Store whether avatar is sitting in a setting

This commit is contained in:
Atlante45 2017-02-27 16:32:34 -08:00
parent 9ce10742ec
commit cd10b828dd

View file

@ -1,6 +1,7 @@
(function() { (function() {
Script.include("/~/system/libraries/utils.js"); Script.include("/~/system/libraries/utils.js");
var SETTING_KEY = "com.highfidelity.avatar.isSitting";
var ROLE = "fly"; var ROLE = "fly";
var ANIMATION_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/clement/production/animations/sitting_idle.fbx"; var ANIMATION_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/clement/production/animations/sitting_idle.fbx";
var ANIMATION_FPS = 30; var ANIMATION_FPS = 30;
@ -77,23 +78,28 @@
return; return;
} }
that.setSeatUser(MyAvatar.sessionUUID); this.setSeatUser(MyAvatar.sessionUUID);
MyAvatar.characterControllerEnabled = false;
MyAvatar.hmdLeanRecenterEnabled = false;
MyAvatar.overrideRoleAnimation(ROLE, ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);
MyAvatar.resetSensorsAndBody();
var properties = Entities.getEntityProperties(that.entityID, ["position", "rotation"]); var previousValue = Settings.getValue(SETTING_KEY);
var index = MyAvatar.getJointIndex("Hips"); Settings.setValue(SETTING_KEY, this.entityID);
if (previousValue === "") {
MyAvatar.characterControllerEnabled = false;
MyAvatar.hmdLeanRecenterEnabled = false;
MyAvatar.overrideRoleAnimation(ROLE, ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);
}
MyAvatar.resetSensorsAndBody();
MyAvatar.bodyRoll = 0.0;
MyAvatar.bodyPitch = 0.0;
var that = this; var that = this;
Script.setTimeout(function() { Script.setTimeout(function() {
var properties = Entities.getEntityProperties(that.entityID, ["position", "rotation"]);
var index = MyAvatar.getJointIndex("Hips");
MyAvatar.pinJoint(index, properties.position, properties.rotation); MyAvatar.pinJoint(index, properties.position, properties.rotation);
that.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(properties) { that.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(properties) {
return { headType: 0 }; return { headType: 0 };
}, ["headType"]); }, ["headType"]);
Script.update.connect(that, that.update); Script.update.connect(that, that.update);
Controller.keyPressEvent.connect(that, that.keyPressed); Controller.keyPressEvent.connect(that, that.keyPressed);
Controller.keyReleaseEvent.connect(that, that.keyReleased); Controller.keyReleaseEvent.connect(that, that.keyReleased);
@ -104,22 +110,27 @@
} }
this.sitUp = function() { this.sitUp = function() {
MyAvatar.restoreRoleAnimation(ROLE);
MyAvatar.characterControllerEnabled = true;
MyAvatar.hmdLeanRecenterEnabled = true;
this.setSeatUser(null); this.setSeatUser(null);
var index = MyAvatar.getJointIndex("Hips"); if (Settings.getValue(SETTING_KEY) === this.entityID) {
MyAvatar.clearPinOnJoint(index); MyAvatar.restoreRoleAnimation(ROLE);
MyAvatar.characterControllerEnabled = true;
MyAvatar.hmdLeanRecenterEnabled = true;
var index = MyAvatar.getJointIndex("Hips");
MyAvatar.clearPinOnJoint(index);
MyAvatar.resetSensorsAndBody();
Script.setTimeout(function() {
MyAvatar.bodyPitch = 0.0;
MyAvatar.bodyRoll = 0.0;
}, SIT_DELAY);
Settings.setValue(SETTING_KEY, "");
}
MyAvatar.removeAnimationStateHandler(this.animStateHandlerID); MyAvatar.removeAnimationStateHandler(this.animStateHandlerID);
Script.setTimeout(function() {
MyAvatar.bodyPitch = 0.0;
MyAvatar.bodyRoll = 0.0;
MyAvatar.resetSensorsAndBody();
}, SIT_DELAY);
Script.update.disconnect(this, this.update); Script.update.disconnect(this, this.update);
Controller.keyPressEvent.disconnect(this, this.keyPressed); Controller.keyPressEvent.disconnect(this, this.keyPressed);
Controller.keyReleaseEvent.disconnect(this, this.keyReleased); Controller.keyReleaseEvent.disconnect(this, this.keyReleased);