Merge pull request #8378 from sethalves/fix-auto-unequip

fix auto-unequip
This commit is contained in:
Philip Rosedale 2016-08-05 18:19:11 -07:00 committed by GitHub
commit da8b075d34

View file

@ -107,7 +107,10 @@ var NEAR_GRAB_PICK_RADIUS = 0.25; // radius used for search ray vs object for ne
var PICK_BACKOFF_DISTANCE = 0.2; // helps when hand is intersecting the grabble object
var NEAR_GRABBING_KINEMATIC = true; // force objects to be kinematic when near-grabbed
var CHECK_TOO_FAR_UNEQUIP_TIME = 1.0; // seconds
// if an equipped item is "adjusted" to be too far from the hand it's in, it will be unequipped.
var CHECK_TOO_FAR_UNEQUIP_TIME = 0.3; // seconds, duration between checks
var AUTO_UNEQUIP_DISTANCE_FACTOR = 1.2; // multiplied by maximum dimension of held item, > this means drop
//
// other constants
@ -1818,7 +1821,8 @@ function MyController(hand) {
this.heartBeat(this.grabbedEntity);
var props = Entities.getEntityProperties(this.grabbedEntity, ["localPosition", "parentID", "position", "rotation"]);
var props = Entities.getEntityProperties(this.grabbedEntity, ["localPosition", "parentID",
"position", "rotation", "dimensions"]);
if (!props.position) {
// server may have reset, taking our equipped entity with it. move back to "off" stte
this.callEntityMethodOnGrabbed("releaseGrab");
@ -1830,10 +1834,9 @@ function MyController(hand) {
if (now - this.lastUnequipCheckTime > MSECS_PER_SEC * CHECK_TOO_FAR_UNEQUIP_TIME) {
this.lastUnequipCheckTime = now;
if (props.parentID == MyAvatar.sessionUUID &&
Vec3.length(props.localPosition) > NEAR_GRAB_MAX_DISTANCE) {
if (props.parentID == MyAvatar.sessionUUID) {
var handPosition = this.getHandPosition();
// the center of the equipped object being far from the hand isn't enough to autoequip -- we also
// the center of the equipped object being far from the hand isn't enough to auto-unequip -- we also
// need to fail the findEntities test.
var nearPickedCandidateEntities = Entities.findEntities(handPosition, NEAR_GRAB_RADIUS);
if (nearPickedCandidateEntities.indexOf(this.grabbedEntity) == -1) {
@ -2416,4 +2419,4 @@ function cleanup() {
}
Script.scriptEnding.connect(cleanup);
Script.update.connect(update);
Script.update.connect(update);