From 7284e3aa3c42e4b188672531411e5f7d3d512f46 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 20 Aug 2015 22:20:51 -0700 Subject: [PATCH] added a little bit of spin, too. --- examples/toys/grenade.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/toys/grenade.js b/examples/toys/grenade.js index 545bfbb982..b2dfebb888 100644 --- a/examples/toys/grenade.js +++ b/examples/toys/grenade.js @@ -166,13 +166,17 @@ function blowShitUp(position, radius) { var stuff = Entities.findEntities(position, radius); var numMoveable = 0; var STRENGTH = 3.5; + var SPIN_RATE = 20.0; for (var i = 0; i < stuff.length; i++) { var properties = Entities.getEntityProperties(stuff[i]); if (properties.collisionsWillMove) { var diff = Vec3.subtract(properties.position, position); var distance = Vec3.length(diff); var velocity = Vec3.sum(properties.velocity, Vec3.multiply(STRENGTH * 1.0 / distance, Vec3.normalize(diff))); - Entities.editEntity(stuff[i], { velocity: velocity }); + var angularVelocity = { x: Math.random() * SPIN_RATE, y: Math.random() * SPIN_RATE, z: Math.random() * SPIN_RATE }; + angularVelocity = Vec3.multiply( 1.0 / distance, angularVelocity); + Entities.editEntity(stuff[i], { velocity: velocity, + angularVelocity: angularVelocity }); } } }