diff --git a/examples/toys/breakdanceCore.js b/examples/toys/breakdanceCore.js index eeb4e137a2..57a679ff51 100644 --- a/examples/toys/breakdanceCore.js +++ b/examples/toys/breakdanceCore.js @@ -12,62 +12,46 @@ function getPuppetPosition(props) { - print ("getPuppetPosition..."); var MAX_DISTANCE = 10; var searchPosition = MyAvatar.position; -print ("getPuppetPosition... line: A" ); - if (props !== undefined && props.position !== undefined) { searchPosition = props.position; } -print ("getPuppetPosition... line: B"); - // first look for the "Table 1" entity -Vec3.print("searchPosition:", searchPosition); - var ids = Entities.findEntities(searchPosition, MAX_DISTANCE); -print ("getPuppetPosition... line: C"); -print("ids:"+ ids.toString()); - for (var i in ids) { - -print("i:"+ i); var entityId = ids[i]; - -print ("findEntities entityId:" + entityId); - var foundProps = Entities.getEntityProperties(entityId); - print ("foundProps.name:" + foundProps.name); - if (foundProps.name == "Table 1") { - Vec3.print("foundProps.center:", foundProps.boundingBox.center); + // we want to keep the puppet to be bound to the x/z bouds of the table + // and placed at the top of the table suface. But we want to generally position + // the puppet at the x/z of where the toy was grabbed. - position = foundProps.boundingBox.center; + var minX = foundProps.boundingBox.brn.x + (props.dimensions.x / 2); + var maxX = foundProps.boundingBox.tfl.x - (props.dimensions.x / 2); + var minZ = foundProps.boundingBox.brn.z + (props.dimensions.z / 2); + var maxZ = foundProps.boundingBox.tfl.z - (props.dimensions.z / 2); - position.y += foundProps.boundingBox.dimensions.y / 2; + var bestX = Math.min(maxX, Math.max(props.position.x, minX)); + var bestZ = Math.min(maxZ, Math.max(props.position.z, minZ)); - Vec3.print("found table 1 center, position:", position); + // Adjust the position to be the "top" of the table. Note: this assumes the table has registrationPoint of 0.5 + // this also assumes the table hasn't been rotated in such a manner that the table top isn't flat + var bestY = foundProps.boundingBox.center.y + (foundProps.boundingBox.dimensions.y / 2); -print ("getPuppetPosition... line: D"); - - Vec3.print("found table 1 center, position:", position); + position = { x: bestX, y: bestY, z: bestZ }; return position; } } -print ("getPuppetPosition... line: E"); - if (props !== undefined && props.position !== undefined) { - Vec3.print("props.position:", props.position); return props.position; } -print ("getPuppetPosition... line: F"); - var DISTANCE_IN_FRONT = 2; var DISTANCE_UP = 0.4; var DISTANCE_TO_SIDE = 0.0; @@ -84,10 +68,6 @@ print ("getPuppetPosition... line: F"); var offset = Vec3.sum(Vec3.sum(leftOffset, frontOffset), upOffset); var position = Vec3.sum(MyAvatar.position, offset); - Vec3.print("default, position:", position); - -print ("getPuppetPosition... line: G"); - return position; }