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+
111 (function() {
212 Script.include("/~/system/libraries/utils.js");
3−
13+
414 var SETTING_KEY = "com.highfidelity.avatar.isSitting";
515 var ANIMATION_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/clement/production/animations/sitting_idle.fbx";
616 var ANIMATION_FPS = 30;
@@ -28,6 +38,7 @@ · 21 unmodified lines
2838 this.interval = null;
2939 this.sitDownSettlePeriod = null;
3040 this.lastTimeNoDriveKeys = null;
41+ this.sittingDown = false;
3142
3243 this.preload = function(entityID) {
3344 this.entityID = entityID;
@@ -106,6 +117,7 @@ · 72 unmodified lines
106117 return;
107118 }
108119 print("Sitting down (" + this.entityID + ")");
120+ this.sittingDown = true;
109121
110122 var now = Date.now();
111123 this.sitDownSettlePeriod = now + IK_SETTLE_TIME;
@@ -121,6 +133,11 @@ · 9 unmodified lines
121133 for (i in ROLES) {
122134 MyAvatar.overrideRoleAnimation(ROLES[i], ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);
123135 }
136+
137+ for (var i in OVERRIDEN_DRIVE_KEYS) {
138+ MyAvatar.disableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
139+ }
140+
124141 MyAvatar.resetSensorsAndBody();
125142 }
126143
@@ -132,22 +149,21 @@ · 5 unmodified lines
132149 return { headType: 0 };
133150 }, ["headType"]);
134151 Script.update.connect(this, this.update);
135− for (var i in OVERRIDEN_DRIVE_KEYS) {
136− MyAvatar.disableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
137− }
138152 }
139153
140154 this.standUp = function() {
141155 print("Standing up (" + this.entityID + ")");
142156 MyAvatar.removeAnimationStateHandler(this.animStateHandlerID);
143157 Script.update.disconnect(this, this.update);
144− for (var i in OVERRIDEN_DRIVE_KEYS) {
145− MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
146− }
147158
148159 this.setSeatUser(null);
149160 if (Settings.getValue(SETTING_KEY) === this.entityID) {
150161 Settings.setValue(SETTING_KEY, "");
162+
163+ for (var i in OVERRIDEN_DRIVE_KEYS) {
164+ MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
165+ }
166+
151167 var ROLES = MyAvatar.getAnimationRoles();
152168 for (i in ROLES) {
153169 MyAvatar.restoreRoleAnimation(ROLES[i]);
@@ -165,6 +181,7 @@ · 11 unmodified lines
165181 MyAvatar.bodyRoll = 0.0;
166182 }, SIT_DELAY);
167183 }
184+ this.sittingDown = false;
168185 }
169186
170187 // function called by teleport.js if it detects the appropriate userData
@@ -215,7 +232,7 @@ · 44 unmodified lines
215232 }
216233
217234 this.update = function(dt) {
218− if (MyAvatar.sessionUUID === this.getSeatUser()) {
235+ if (this.sittingDown === true) {
219236 var properties = Entities.getEntityProperties(this.entityID);
220237 var avatarDistance = Vec3.distance(MyAvatar.position, properties.position);
221238 var ikError = MyAvatar.getIKErrorOnLastSolve();