History

Remove Avatar parenting to chair

Atlante45 committed 9 years ago

Commit 68e3e231 parent cbaaaa21 file · +41 −13Browse files

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

Unified · Split

scripts/tutorials/entity_scripts/sit.js+41−13
@@ -22,7 +22,7 @@ · 21 unmodified lines
2222 this.entityID = entityID;
2323 }
2424 this.unload = function() {
25− if (MyAvatar.getParentID() === this.entityID) {
25+ if (MyAvatar.sessionUUID === this.getSeatUser()) {
2626 this.sitUp(this.entityID);
2727 }
2828 if (this.interval) {
@@ -32,11 +32,39 @@ · 3 unmodified lines
3232 this.cleanupOverlay();
3333 }
3434
35+ this.setSeatUser = function(user) {
36+ var userData = Entities.getEntityProperties(this.entityID, ["userData"]).userData;
37+ userData = JSON.parse(userData);
38+
39+ if (user) {
40+ userData.seat.user = user;
41+ } else {
42+ delete userData.seat.user;
43+ }
44+
45+ Entities.editEntity(this.entityID, {
46+ userData: JSON.stringify(userData)
47+ });
48+ }
49+ this.getSeatUser = function() {
50+ var properties = Entities.getEntityProperties(this.entityID, ["userData", "position"]);
51+ var userData = JSON.parse(properties.userData);
52+
53+ if (userData.seat.user && userData.seat.user !== MyAvatar.sessionUUID) {
54+ var avatar = AvatarList.getAvatar(userData.seat.user);
55+ if (avatar && Vec3.distance(avatar.position, properties.position) > RELEASE_DISTANCE) {
56+ return null;
57+ }
58+ }
59+ return userData.seat.user;
60+ }
61+
3562 this.checkSeatForAvatar = function() {
63+ var seatUser = this.getSeatUser();
3664 var avatarIdentifiers = AvatarList.getAvatarIdentifiers();
3765 for (var i in avatarIdentifiers) {
3866 var avatar = AvatarList.getAvatar(avatarIdentifiers[i]);
39− if (avatar && avatar.getParentID() === this.entityID) {
67+ if (avatar && avatar.sessionUUID === seatUser) {
4068 return true;
4169 }
4270 }
@@ -53,7 +81,7 @@ · 10 unmodified lines
5381
5482 var that = this;
5583 Script.setTimeout(function() {
56− MyAvatar.setParentID(that.entityID);
84+ that.setSeatUser(MyAvatar.sessionUUID);
5785 MyAvatar.characterControllerEnabled = false;
5886 MyAvatar.hmdLeanRecenterEnabled = false;
5987 MyAvatar.overrideRoleAnimation(ROLE, ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);
@@ -62,7 +90,7 @@ · 2 unmodified lines
6290 var index = MyAvatar.getJointIndex("Hips");
6391 MyAvatar.pinJoint(index, properties.position, properties.rotation);
6492
65− that.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(props) {
93+ that.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(properties) {
6694 return { headType: 0 };
6795 }, ["headType"]);
6896
@@ -82,7 +110,7 @@ · 13 unmodified lines
82110 MyAvatar.restoreRoleAnimation(ROLE);
83111 MyAvatar.characterControllerEnabled = true;
84112 MyAvatar.hmdLeanRecenterEnabled = true;
85− MyAvatar.setParentID("");
113+ this.setSeatUser(null);
86114
87115 var index = MyAvatar.getJointIndex("Hips");
88116 MyAvatar.clearPinOnJoint(index);
@@ -130,9 +158,9 @@ · 41 unmodified lines
130158 x: textSize.width + 2 * textMargin,
131159 y: textSize.height + 2 * textMargin
132160 }
133− var props = Entities.getEntityProperties(this.entityID, ["position", "registrationPoint", "dimensions"]);
134− var yOffset = (1.0 - props.registrationPoint.y) * props.dimensions.y + (overlayDimensions.y / 2.0);
135− var overlayPosition = Vec3.sum(props.position, { x: 0, y: yOffset, z: 0 });
161+ var properties = Entities.getEntityProperties(this.entityID, ["position", "registrationPoint", "dimensions"]);
162+ var yOffset = (1.0 - properties.registrationPoint.y) * properties.dimensions.y + (overlayDimensions.y / 2.0);
163+ var overlayPosition = Vec3.sum(properties.position, { x: 0, y: yOffset, z: 0 });
136164 Overlays.editOverlay(this.overlay, {
137165 position: overlayPosition,
138166 dimensions: overlayDimensions
@@ -147,7 +175,7 @@ · 8 unmodified lines
147175
148176
149177 this.update = function(dt) {
150− if (MyAvatar.getParentID() === this.entityID) {
178+ if (MyAvatar.sessionUUID === this.getSeatUser()) {
151179 var properties = Entities.getEntityProperties(this.entityID, ["position"]);
152180 var avatarDistance = Vec3.distance(MyAvatar.position, properties.position);
153181 var ikError = MyAvatar.getIKErrorOnLastSolve();
@@ -179,13 +207,13 @@ · 25 unmodified lines
179207 }
180208
181209 this.canSitDesktop = function() {
182− var props = Entities.getEntityProperties(this.entityID, ["position"]);
183− var distanceFromSeat = Vec3.distance(MyAvatar.position, props.position);
210+ var properties = Entities.getEntityProperties(this.entityID, ["position"]);
211+ var distanceFromSeat = Vec3.distance(MyAvatar.position, properties.position);
184212 return distanceFromSeat < DESKTOP_MAX_DISTANCE && !this.checkSeatForAvatar();
185213 }
186214
187215 this.hoverEnterEntity = function(event) {
188− if (isInEditMode() || (MyAvatar.getParentID() === this.entityID)) {
216+ if (isInEditMode() || (MyAvatar.sessionUUID === this.getSeatUser())) {
189217 return;
190218 }
191219
@@ -209,7 +237,7 @@ · 17 unmodified lines
209237 }
210238
211239 this.clickDownOnEntity = function () {
212− if (isInEditMode() || (MyAvatar.getParentID() === this.entityID)) {
240+ if (isInEditMode() || (MyAvatar.sessionUUID === this.getSeatUser())) {
213241 return;
214242 }
215243 if (this.canSitDesktop()) {