History

Fix a couple sitting bugs

Atlante45 committed 9 years ago

Commit c1466c21 parent 69879121 file · +25 −8Browse files

Showing the changes to scripts/tutorials/entity_scripts (1 of 1 file). Show all

Unified · Split

scripts/tutorials/entity_scripts/sit.js+25−8
@@ -1,6 +1,16 @@
1//
2// sit.js
3//
4// Created by Clement Brisset on 3/3/17
5// Copyright 2017 High Fidelity, Inc.
6//
7// Distributed under the Apache License, Version 2.0.
8// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9//
10
1(function() {11(function() {
2 Script.include("/~/system/libraries/utils.js");12 Script.include("/~/system/libraries/utils.js");
3 13
4 var SETTING_KEY = "com.highfidelity.avatar.isSitting";14 var SETTING_KEY = "com.highfidelity.avatar.isSitting";
5 var ANIMATION_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/clement/production/animations/sitting_idle.fbx";15 var ANIMATION_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/clement/production/animations/sitting_idle.fbx";
6 var ANIMATION_FPS = 30;16 var ANIMATION_FPS = 30;
@@ -28,6 +38,7 @@ · 21 unmodified lines
28 this.interval = null;38 this.interval = null;
29 this.sitDownSettlePeriod = null;39 this.sitDownSettlePeriod = null;
30 this.lastTimeNoDriveKeys = null;40 this.lastTimeNoDriveKeys = null;
41 this.sittingDown = false;
31 42
32 this.preload = function(entityID) {43 this.preload = function(entityID) {
33 this.entityID = entityID;44 this.entityID = entityID;
@@ -106,6 +117,7 @@ · 72 unmodified lines
106 return;117 return;
107 }118 }
108 print("Sitting down (" + this.entityID + ")");119 print("Sitting down (" + this.entityID + ")");
120 this.sittingDown = true;
109 121
110 var now = Date.now();122 var now = Date.now();
111 this.sitDownSettlePeriod = now + IK_SETTLE_TIME;123 this.sitDownSettlePeriod = now + IK_SETTLE_TIME;
@@ -121,6 +133,11 @@ · 9 unmodified lines
121 for (i in ROLES) {133 for (i in ROLES) {
122 MyAvatar.overrideRoleAnimation(ROLES[i], ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);134 MyAvatar.overrideRoleAnimation(ROLES[i], ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);
123 }135 }
136
137 for (var i in OVERRIDEN_DRIVE_KEYS) {
138 MyAvatar.disableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
139 }
140
124 MyAvatar.resetSensorsAndBody();141 MyAvatar.resetSensorsAndBody();
125 }142 }
126 143
@@ -132,22 +149,21 @@ · 5 unmodified lines
132 return { headType: 0 };149 return { headType: 0 };
133 }, ["headType"]);150 }, ["headType"]);
134 Script.update.connect(this, this.update);151 Script.update.connect(this, this.update);
135 for (var i in OVERRIDEN_DRIVE_KEYS) {
136 MyAvatar.disableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
137 }
138 }152 }
139 153
140 this.standUp = function() {154 this.standUp = function() {
141 print("Standing up (" + this.entityID + ")");155 print("Standing up (" + this.entityID + ")");
142 MyAvatar.removeAnimationStateHandler(this.animStateHandlerID);156 MyAvatar.removeAnimationStateHandler(this.animStateHandlerID);
143 Script.update.disconnect(this, this.update);157 Script.update.disconnect(this, this.update);
144 for (var i in OVERRIDEN_DRIVE_KEYS) {
145 MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
146 }
147 158
148 this.setSeatUser(null);159 this.setSeatUser(null);
149 if (Settings.getValue(SETTING_KEY) === this.entityID) {160 if (Settings.getValue(SETTING_KEY) === this.entityID) {
150 Settings.setValue(SETTING_KEY, "");161 Settings.setValue(SETTING_KEY, "");
162
163 for (var i in OVERRIDEN_DRIVE_KEYS) {
164 MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
165 }
166
151 var ROLES = MyAvatar.getAnimationRoles();167 var ROLES = MyAvatar.getAnimationRoles();
152 for (i in ROLES) {168 for (i in ROLES) {
153 MyAvatar.restoreRoleAnimation(ROLES[i]);169 MyAvatar.restoreRoleAnimation(ROLES[i]);
@@ -165,6 +181,7 @@ · 11 unmodified lines
165 MyAvatar.bodyRoll = 0.0;181 MyAvatar.bodyRoll = 0.0;
166 }, SIT_DELAY);182 }, SIT_DELAY);
167 }183 }
184 this.sittingDown = false;
168 }185 }
169 186
170 // function called by teleport.js if it detects the appropriate userData187 // function called by teleport.js if it detects the appropriate userData
@@ -215,7 +232,7 @@ · 44 unmodified lines
215 }232 }
216 233
217 this.update = function(dt) {234 this.update = function(dt) {
218 if (MyAvatar.sessionUUID === this.getSeatUser()) {235 if (this.sittingDown === true) {
219 var properties = Entities.getEntityProperties(this.entityID);236 var properties = Entities.getEntityProperties(this.entityID);
220 var avatarDistance = Vec3.distance(MyAvatar.position, properties.position);237 var avatarDistance = Vec3.distance(MyAvatar.position, properties.position);
221 var ikError = MyAvatar.getIKErrorOnLastSolve();238 var ikError = MyAvatar.getIKErrorOnLastSolve();