From 7824d03e11b4918fad6861da769b928622cc3919 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 9 Oct 2015 17:56:32 -0700 Subject: [PATCH] grab script picks 5x per second rather than 60x --- examples/controllers/handControllerGrab.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 47bcc0083c..e040befdf8 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -67,6 +67,8 @@ var MSEC_PER_SEC = 1000.0; var startTime = Date.now(); var LIFETIME = 10; var ACTION_LIFETIME = 10; // seconds +var PICKS_PER_SECOND_PER_HAND = 5; +var MSECS_PER_SEC = 1000.0; // states for the state machine var STATE_OFF = 0; @@ -234,6 +236,7 @@ function MyController(hand, triggerAction) { this.off = function() { if (this.triggerSmoothedSqueezed()) { + this.lastPickTime = 0; this.setState(STATE_SEARCHING); return; } @@ -258,6 +261,13 @@ function MyController(hand, triggerAction) { grabbable: true }; + // don't pick 60x per second. do this check after updating the line so it's not jumpy. + var now = Date.now(); + if (now - this.lastPickTime < MSECS_PER_SEC / PICKS_PER_SECOND_PER_HAND) { + return; + } + this.lastPickTime = now; + var intersection = Entities.findRayIntersection(pickRay, true); if (intersection.intersects && intersection.properties.locked === 0) { // the ray is intersecting something we can move.