mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:17:02 +02:00
Merge pull request #9940 from Atlante45/fix/sit
Fix a few sitting bugs noticed at the meetup
This commit is contained in:
commit
82114ae6ab
2 changed files with 62 additions and 15 deletions
|
@ -441,7 +441,12 @@ function getTeleportTargetType(intersection) {
|
||||||
var props = Entities.getEntityProperties(intersection.entityID, ['userData', 'visible']);
|
var props = Entities.getEntityProperties(intersection.entityID, ['userData', 'visible']);
|
||||||
var data = parseJSON(props.userData);
|
var data = parseJSON(props.userData);
|
||||||
if (data !== undefined && data.seat !== undefined) {
|
if (data !== undefined && data.seat !== undefined) {
|
||||||
return TARGET.SEAT;
|
var avatarUuid = Uuid.fromString(data.seat.user);
|
||||||
|
if (Uuid.isNull(avatarUuid) || !AvatarList.getAvatar(avatarUuid)) {
|
||||||
|
return TARGET.SEAT;
|
||||||
|
} else {
|
||||||
|
return TARGET.INVALID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!props.visible) {
|
if (!props.visible) {
|
||||||
|
|
|
@ -1,5 +1,21 @@
|
||||||
|
//
|
||||||
|
// sit.js
|
||||||
|
//
|
||||||
|
// Created by Clement Brisset on 3/3/17
|
||||||
|
// Copyright 2017 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
Script.include("/~/system/libraries/utils.js");
|
Script.include("/~/system/libraries/utils.js");
|
||||||
|
if (!String.prototype.startsWith) {
|
||||||
|
String.prototype.startsWith = function(searchString, position){
|
||||||
|
position = position || 0;
|
||||||
|
return this.substr(position, searchString.length) === searchString;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var SETTING_KEY = "com.highfidelity.avatar.isSitting";
|
var SETTING_KEY = "com.highfidelity.avatar.isSitting";
|
||||||
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";
|
||||||
|
@ -28,6 +44,10 @@
|
||||||
this.interval = null;
|
this.interval = null;
|
||||||
this.sitDownSettlePeriod = null;
|
this.sitDownSettlePeriod = null;
|
||||||
this.lastTimeNoDriveKeys = null;
|
this.lastTimeNoDriveKeys = null;
|
||||||
|
this.sittingDown = false;
|
||||||
|
|
||||||
|
// Preload the animation file
|
||||||
|
this.animation = AnimationCache.prefetch(ANIMATION_URL);
|
||||||
|
|
||||||
this.preload = function(entityID) {
|
this.preload = function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
|
@ -100,12 +120,19 @@
|
||||||
return seatUser !== null;
|
return seatUser !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.rolesToOverride = function() {
|
||||||
|
return MyAvatar.getAnimationRoles().filter(function(role) {
|
||||||
|
return role === "fly" || role.startsWith("inAir");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.sitDown = function() {
|
this.sitDown = function() {
|
||||||
if (this.checkSeatForAvatar()) {
|
if (this.checkSeatForAvatar()) {
|
||||||
print("Someone is already sitting in that chair.");
|
print("Someone is already sitting in that chair.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
print("Sitting down (" + this.entityID + ")");
|
print("Sitting down (" + this.entityID + ")");
|
||||||
|
this.sittingDown = true;
|
||||||
|
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
this.sitDownSettlePeriod = now + IK_SETTLE_TIME;
|
this.sitDownSettlePeriod = now + IK_SETTLE_TIME;
|
||||||
|
@ -117,10 +144,15 @@
|
||||||
if (previousValue === "") {
|
if (previousValue === "") {
|
||||||
MyAvatar.characterControllerEnabled = false;
|
MyAvatar.characterControllerEnabled = false;
|
||||||
MyAvatar.hmdLeanRecenterEnabled = false;
|
MyAvatar.hmdLeanRecenterEnabled = false;
|
||||||
var ROLES = MyAvatar.getAnimationRoles();
|
var roles = this.rolesToOverride();
|
||||||
for (i in ROLES) {
|
for (i in roles) {
|
||||||
MyAvatar.overrideRoleAnimation(ROLES[i], ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);
|
MyAvatar.overrideRoleAnimation(roles[i], ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var i in OVERRIDEN_DRIVE_KEYS) {
|
||||||
|
MyAvatar.disableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
|
||||||
|
}
|
||||||
|
|
||||||
MyAvatar.resetSensorsAndBody();
|
MyAvatar.resetSensorsAndBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,25 +164,27 @@
|
||||||
return { headType: 0 };
|
return { headType: 0 };
|
||||||
}, ["headType"]);
|
}, ["headType"]);
|
||||||
Script.update.connect(this, this.update);
|
Script.update.connect(this, this.update);
|
||||||
for (var i in OVERRIDEN_DRIVE_KEYS) {
|
|
||||||
MyAvatar.disableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.standUp = function() {
|
this.standUp = function() {
|
||||||
print("Standing up (" + this.entityID + ")");
|
print("Standing up (" + this.entityID + ")");
|
||||||
MyAvatar.removeAnimationStateHandler(this.animStateHandlerID);
|
MyAvatar.removeAnimationStateHandler(this.animStateHandlerID);
|
||||||
Script.update.disconnect(this, this.update);
|
Script.update.disconnect(this, this.update);
|
||||||
for (var i in OVERRIDEN_DRIVE_KEYS) {
|
|
||||||
MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
|
if (MyAvatar.sessionUUID === this.getSeatUser()) {
|
||||||
|
this.setSeatUser(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setSeatUser(null);
|
|
||||||
if (Settings.getValue(SETTING_KEY) === this.entityID) {
|
if (Settings.getValue(SETTING_KEY) === this.entityID) {
|
||||||
Settings.setValue(SETTING_KEY, "");
|
Settings.setValue(SETTING_KEY, "");
|
||||||
var ROLES = MyAvatar.getAnimationRoles();
|
|
||||||
for (i in ROLES) {
|
for (var i in OVERRIDEN_DRIVE_KEYS) {
|
||||||
MyAvatar.restoreRoleAnimation(ROLES[i]);
|
MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var roles = this.rolesToOverride();
|
||||||
|
for (i in roles) {
|
||||||
|
MyAvatar.restoreRoleAnimation(roles[i]);
|
||||||
}
|
}
|
||||||
MyAvatar.characterControllerEnabled = true;
|
MyAvatar.characterControllerEnabled = true;
|
||||||
MyAvatar.hmdLeanRecenterEnabled = true;
|
MyAvatar.hmdLeanRecenterEnabled = true;
|
||||||
|
@ -165,6 +199,7 @@
|
||||||
MyAvatar.bodyRoll = 0.0;
|
MyAvatar.bodyRoll = 0.0;
|
||||||
}, SIT_DELAY);
|
}, SIT_DELAY);
|
||||||
}
|
}
|
||||||
|
this.sittingDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// function called by teleport.js if it detects the appropriate userData
|
// function called by teleport.js if it detects the appropriate userData
|
||||||
|
@ -215,7 +250,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update = function(dt) {
|
this.update = function(dt) {
|
||||||
if (MyAvatar.sessionUUID === this.getSeatUser()) {
|
if (this.sittingDown === true) {
|
||||||
var properties = Entities.getEntityProperties(this.entityID);
|
var properties = Entities.getEntityProperties(this.entityID);
|
||||||
var avatarDistance = Vec3.distance(MyAvatar.position, properties.position);
|
var avatarDistance = Vec3.distance(MyAvatar.position, properties.position);
|
||||||
var ikError = MyAvatar.getIKErrorOnLastSolve();
|
var ikError = MyAvatar.getIKErrorOnLastSolve();
|
||||||
|
@ -244,6 +279,9 @@
|
||||||
shouldStandUp = true;
|
shouldStandUp = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MyAvatar.sessionUUID !== this.getSeatUser()) {
|
||||||
|
shouldStandUp = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldStandUp || avatarDistance > RELEASE_DISTANCE) {
|
if (shouldStandUp || avatarDistance > RELEASE_DISTANCE) {
|
||||||
print("IK error: " + ikError + ", distance from chair: " + avatarDistance);
|
print("IK error: " + ikError + ", distance from chair: " + avatarDistance);
|
||||||
|
@ -253,7 +291,11 @@
|
||||||
var offset = { x: 0, y: 1.0, z: -0.5 - properties.dimensions.z * properties.registrationPoint.z };
|
var offset = { x: 0, y: 1.0, z: -0.5 - properties.dimensions.z * properties.registrationPoint.z };
|
||||||
var position = Vec3.sum(properties.position, Vec3.multiplyQbyV(properties.rotation, offset));
|
var position = Vec3.sum(properties.position, Vec3.multiplyQbyV(properties.rotation, offset));
|
||||||
MyAvatar.position = position;
|
MyAvatar.position = position;
|
||||||
print("Moving Avatar in front of the chair.")
|
print("Moving Avatar in front of the chair.");
|
||||||
|
// Delay standing up by 1 cycle.
|
||||||
|
// This leaves times for the avatar to actually move since a lot
|
||||||
|
// of the stand up operations are threaded
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.standUp();
|
this.standUp();
|
||||||
|
|
Loading…
Reference in a new issue