From 7c8050790b3060207b0dc52ac3cc33e65d1bf38f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 1 Apr 2016 14:20:36 -0700 Subject: [PATCH] set velocity when something is un-parent-grabbed --- examples/controllers/handControllerGrab.js | 18 +++++++++++++++++- examples/defaultScripts.js | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 6a15c57232..d2260012f3 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1562,6 +1562,10 @@ function MyController(hand) { var deltaPosition = Vec3.subtract(handControllerPosition, this.currentHandControllerTipPosition); // meters var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds + if (deltaTime > 0.0) { + this.currentVelocity = Vec3.multiply(deltaPosition, 1.0 / deltaTime); + } + this.currentHandControllerTipPosition = handControllerPosition; this.currentObjectTime = now; @@ -1886,9 +1890,21 @@ function MyController(hand) { // things that are held by parenting and dropped with no velocity will end up as "static" in bullet. If // it looks like the dropped thing should fall, give it a little velocity. - var parentID = Entities.getEntityProperties(entityID, ["parentID"]).parentID; + var props = Entities.getEntityProperties(entityID, ["parentID", "velocity"]) + var parentID = props.parentID; var forceVelocity = false; + + deactiveProps["velocity"] = props.velocity; + if (parentID != NULL_UUID) { + // TODO: EntityScriptingInterface::convertLocationToScriptSemantics should be setting up + // props.velocity to be a world-frame velocity and localVelocity to be vs parent. Until that + // is done, we use a measured velocity here so that things held via a bumper-grab / parenting-grab + // can be thrown. + deactiveProps["velocity"] = this.currentVelocity; + } + if (!noVelocity && + vec3equal(deactiveProps.velocity, ZERO_VEC) && parentID == MyAvatar.sessionUUID && Vec3.length(data["gravity"]) > 0.0 && data["dynamic"] && diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index ab3ff956d4..65c4fb315b 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -20,5 +20,5 @@ Script.load("controllers/squeezeHands.js"); Script.load("grab.js"); Script.load("directory.js"); Script.load("dialTone.js"); -Script.load("attachedEntitiesManager.js"); +// Script.load("attachedEntitiesManager.js"); Script.load("depthReticle.js");