Showing the changes to scripts/tutorials/entity_scripts (1 of 1 file). Show all
Unified · Split
| @@ -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 | 11 | (function() { |
| 2 | 12 | Script.include("/~/system/libraries/utils.js"); |
| 3 | − | |
| 13 | + | |
| 4 | 14 | var SETTING_KEY = "com.highfidelity.avatar.isSitting"; |
| 5 | 15 | var ANIMATION_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/clement/production/animations/sitting_idle.fbx"; |
| 6 | 16 | var ANIMATION_FPS = 30; |
| @@ -28,6 +38,7 @@ · 21 unmodified lines | ||
| 28 | 38 | this.interval = null; |
| 29 | 39 | this.sitDownSettlePeriod = null; |
| 30 | 40 | this.lastTimeNoDriveKeys = null; |
| 41 | + this.sittingDown = false; | |
| 31 | 42 | |
| 32 | 43 | this.preload = function(entityID) { |
| 33 | 44 | this.entityID = entityID; |
| @@ -106,6 +117,7 @@ · 72 unmodified lines | ||
| 106 | 117 | return; |
| 107 | 118 | } |
| 108 | 119 | print("Sitting down (" + this.entityID + ")"); |
| 120 | + this.sittingDown = true; | |
| 109 | 121 | |
| 110 | 122 | var now = Date.now(); |
| 111 | 123 | this.sitDownSettlePeriod = now + IK_SETTLE_TIME; |
| @@ -121,6 +133,11 @@ · 9 unmodified lines | ||
| 121 | 133 | for (i in ROLES) { |
| 122 | 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 | 141 | MyAvatar.resetSensorsAndBody(); |
| 125 | 142 | } |
| 126 | 143 | |
| @@ -132,22 +149,21 @@ · 5 unmodified lines | ||
| 132 | 149 | return { headType: 0 }; |
| 133 | 150 | }, ["headType"]); |
| 134 | 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 | 154 | this.standUp = function() { |
| 141 | 155 | print("Standing up (" + this.entityID + ")"); |
| 142 | 156 | MyAvatar.removeAnimationStateHandler(this.animStateHandlerID); |
| 143 | 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 | 159 | this.setSeatUser(null); |
| 149 | 160 | if (Settings.getValue(SETTING_KEY) === this.entityID) { |
| 150 | 161 | Settings.setValue(SETTING_KEY, ""); |
| 162 | + | |
| 163 | + for (var i in OVERRIDEN_DRIVE_KEYS) { | |
| 164 | + MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS[i]); | |
| 165 | + } | |
| 166 | + | |
| 151 | 167 | var ROLES = MyAvatar.getAnimationRoles(); |
| 152 | 168 | for (i in ROLES) { |
| 153 | 169 | MyAvatar.restoreRoleAnimation(ROLES[i]); |
| @@ -165,6 +181,7 @@ · 11 unmodified lines | ||
| 165 | 181 | MyAvatar.bodyRoll = 0.0; |
| 166 | 182 | }, SIT_DELAY); |
| 167 | 183 | } |
| 184 | + this.sittingDown = false; | |
| 168 | 185 | } |
| 169 | 186 | |
| 170 | 187 | // function called by teleport.js if it detects the appropriate userData |
| @@ -215,7 +232,7 @@ · 44 unmodified lines | ||
| 215 | 232 | } |
| 216 | 233 | |
| 217 | 234 | this.update = function(dt) { |
| 218 | − if (MyAvatar.sessionUUID === this.getSeatUser()) { | |
| 235 | + if (this.sittingDown === true) { | |
| 219 | 236 | var properties = Entities.getEntityProperties(this.entityID); |
| 220 | 237 | var avatarDistance = Vec3.distance(MyAvatar.position, properties.position); |
| 221 | 238 | var ikError = MyAvatar.getIKErrorOnLastSolve(); |