mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:21:16 +02:00
Put avatar in front of chair on situp to avoid infinite collisions
This commit is contained in:
parent
1a375432e0
commit
f0d971fc6f
1 changed files with 35 additions and 6 deletions
|
@ -14,6 +14,7 @@
|
||||||
var DESKTOP_UI_CHECK_INTERVAL = 250;
|
var DESKTOP_UI_CHECK_INTERVAL = 250;
|
||||||
var DESKTOP_MAX_DISTANCE = 5;
|
var DESKTOP_MAX_DISTANCE = 5;
|
||||||
var SIT_DELAY = 25
|
var SIT_DELAY = 25
|
||||||
|
var MAX_RESET_DISTANCE = 0.5
|
||||||
|
|
||||||
this.entityID = null;
|
this.entityID = null;
|
||||||
this.timers = {};
|
this.timers = {};
|
||||||
|
@ -24,7 +25,7 @@
|
||||||
}
|
}
|
||||||
this.unload = function() {
|
this.unload = function() {
|
||||||
if (MyAvatar.sessionUUID === this.getSeatUser()) {
|
if (MyAvatar.sessionUUID === this.getSeatUser()) {
|
||||||
this.sitUp(this.entityID);
|
this.sitUp();
|
||||||
}
|
}
|
||||||
if (this.interval) {
|
if (this.interval) {
|
||||||
Script.clearInterval(this.interval);
|
Script.clearInterval(this.interval);
|
||||||
|
@ -110,9 +111,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sitUp = function() {
|
this.sitUp = function() {
|
||||||
|
if (MyAvatar.sessionUUID !== this.getSeatUser()) {
|
||||||
|
// Duplicate call, bail
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.setSeatUser(null);
|
this.setSeatUser(null);
|
||||||
|
|
||||||
if (Settings.getValue(SETTING_KEY) === this.entityID) {
|
if (Settings.getValue(SETTING_KEY) === this.entityID) {
|
||||||
for (i in ROLES) {
|
for (i in ROLES) {
|
||||||
MyAvatar.restoreRoleAnimation(ROLES[i]);
|
MyAvatar.restoreRoleAnimation(ROLES[i]);
|
||||||
}
|
}
|
||||||
|
@ -187,15 +192,26 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.update = function(dt) {
|
this.update = function(dt) {
|
||||||
if (MyAvatar.sessionUUID === this.getSeatUser()) {
|
if (MyAvatar.sessionUUID === this.getSeatUser()) {
|
||||||
var properties = Entities.getEntityProperties(this.entityID, ["position"]);
|
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();
|
||||||
if (avatarDistance > RELEASE_DISTANCE || ikError > MAX_IK_ERROR) {
|
if (avatarDistance > RELEASE_DISTANCE || ikError > MAX_IK_ERROR) {
|
||||||
print("IK error: " + ikError + ", distance from chair: " + avatarDistance);
|
print("IK error: " + ikError + ", distance from chair: " + avatarDistance);
|
||||||
this.sitUp(this.entityID);
|
|
||||||
|
// Move avatar in front of the chair to avoid getting stuck in collision hulls
|
||||||
|
if (avatarDistance < MAX_RESET_DISTANCE) {
|
||||||
|
var offset = { x: 0, y: 1.0, z: -0.5 - properties.dimensions.z * properties.registrationPoint.z };
|
||||||
|
Vec3.print("offset:", Vec3.multiplyQbyV(properties.rotation, offset));
|
||||||
|
var position = Vec3.sum(properties.position, Vec3.multiplyQbyV(properties.rotation, offset));
|
||||||
|
MyAvatar.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
var that = this;
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
that.sitUp();
|
||||||
|
}, SIT_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +223,20 @@
|
||||||
if (RELEASE_KEYS.indexOf(event.text) !== -1) {
|
if (RELEASE_KEYS.indexOf(event.text) !== -1) {
|
||||||
var that = this;
|
var that = this;
|
||||||
this.timers[event.text] = Script.setTimeout(function() {
|
this.timers[event.text] = Script.setTimeout(function() {
|
||||||
that.sitUp();
|
var properties = Entities.getEntityProperties(that.entityID);
|
||||||
|
var avatarDistance = Vec3.distance(MyAvatar.position, properties.position);
|
||||||
|
|
||||||
|
// Move avatar in front of the chair to avoid getting stuck in collision hulls
|
||||||
|
if (avatarDistance < MAX_RESET_DISTANCE) {
|
||||||
|
var offset = { x: 0, y: 1.0, z: -0.5 - properties.dimensions.z * properties.registrationPoint.z };
|
||||||
|
Vec3.print("offset1:", Vec3.multiplyQbyV(properties.rotation, offset));
|
||||||
|
var position = Vec3.sum(properties.position, Vec3.multiplyQbyV(properties.rotation, offset));
|
||||||
|
MyAvatar.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
that.sitUp();
|
||||||
|
}, SIT_DELAY);
|
||||||
}, RELEASE_TIME);
|
}, RELEASE_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue