cast ray from spout in its direction

This commit is contained in:
ericrius1 2016-02-29 15:06:28 -08:00
parent 03ae48d465
commit b301b71c7d
2 changed files with 42 additions and 15 deletions

View file

@ -60,12 +60,14 @@ var waterCan = Entities.addEntity({
var waterSpoutPosition = Vec3.sum(waterCanPosition, Vec3.multiply(0.2, Quat.getFront(orientation))) var waterSpoutPosition = Vec3.sum(waterCanPosition, Vec3.multiply(0.2, Quat.getFront(orientation)))
var waterSpoutRotation = Quat.multiply(waterCanRotation, Quat.fromPitchYawRollDegrees(30, 0, 0));
var waterSpout = Entities.addEntity({ var waterSpout = Entities.addEntity({
type: "Box", type: "Box",
name: "hifi-water-spout",
dimensions: {x: 0.02, y: 0.02, z: 0.07}, dimensions: {x: 0.02, y: 0.02, z: 0.07},
color: {red: 200, green: 10, blue: 200}, color: {red: 200, green: 10, blue: 200},
position: waterSpoutPosition, position: waterSpoutPosition,
rotation: waterCanRotation, rotation: waterSpoutRotation,
parentID: waterCan parentID: waterCan
}); });

View file

@ -20,6 +20,7 @@
_this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav"); _this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav");
_this.POUR_ANGLE_THRESHOLD = -30; _this.POUR_ANGLE_THRESHOLD = -30;
_this.waterPouring = false; _this.waterPouring = false;
_this.WATER_SPOUT_NAME = "hifi-water-spout";
}; };
@ -33,6 +34,9 @@
}, },
continueHolding: function() { continueHolding: function() {
if (!_this.waterSpout) {
return;
}
// Check rotation of water can along it's z axis. If it's beyond a threshold, then start spraying water // Check rotation of water can along it's z axis. If it's beyond a threshold, then start spraying water
var rotation = Entities.getEntityProperties(_this.entityID, "rotation").rotation; var rotation = Entities.getEntityProperties(_this.entityID, "rotation").rotation;
var pitch = Quat.safeEulerAngles(rotation).x; var pitch = Quat.safeEulerAngles(rotation).x;
@ -43,7 +47,7 @@
Entities.editEntity(_this.waterEffect, {isEmitting: false}); Entities.editEntity(_this.waterEffect, {isEmitting: false});
_this.waterPouring = false; _this.waterPouring = false;
} }
print("PITCH " + pitch); // print("PITCH " + pitch);
}, },
@ -52,8 +56,9 @@
_this.waterEffect = Entities.addEntity({ _this.waterEffect = Entities.addEntity({
type: "ParticleEffect", type: "ParticleEffect",
name: "water particle effect", name: "water particle effect",
position: _this.waterSpoutPosition,
isEmitting: false, isEmitting: false,
position: _this.position, parentID: _this.waterSpout,
colorStart: { colorStart: {
red: 50, red: 50,
green: 50, green: 50,
@ -70,27 +75,28 @@
blue: 60 blue: 60
}, },
maxParticles: 20000, maxParticles: 20000,
lifespan: 10, lifespan: 2,
emitRate: 10000, emitRate: 1000,
emitSpeed: .1, emitSpeed: .2,
speedSpread: 0.0, speedSpread: 0.0,
emitDimensions: { emitDimensions: {
x: 0.1, x: 0,
y: 0.01, y: 0,
z: 0.1 z: 0
}, },
emitAcceleration: { emitAcceleration: {
x: 0.0, x: 0.0,
y: -1.0, y: 0,
z: 0 z: 0
}, },
polarStart: 0, polarStart: 0,
polarFinish: Math.PI, polarFinish: .2,
accelerationSpread: { accelerationSpread: {
x: 0.1, x: 0.01,
y: 0.0, y: 0.0,
z: 0.1 z: 0.01
}, },
emitOrientation: _this.waterSpoutRotation,
particleRadius: 0.04, particleRadius: 0.04,
radiusSpread: 0.01, radiusSpread: 0.01,
radiusStart: 0.03, radiusStart: 0.03,
@ -98,7 +104,8 @@
alphaSpread: .1, alphaSpread: .1,
alphaStart: 0.7, alphaStart: 0.7,
alphaFinish: 0.5, alphaFinish: 0.5,
textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png", emitterShouldTrail: true,
textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png?v2",
}); });
}, },
@ -106,7 +113,25 @@
preload: function(entityID) { preload: function(entityID) {
_this.entityID = entityID; _this.entityID = entityID;
_this.position = Entities.getEntityProperties(_this.entityID, "position").position; _this.position = Entities.getEntityProperties(_this.entityID, "position").position;
// Wait a a bit for spout to spawn for case where preload is initial spawn, then save it
Script.setTimeout(function() {
var entities = Entities.findEntities(_this.position, 1);
entities.forEach (function(entity) {
var name = Entities.getEntityProperties(entity, "name").name;
if (name === _this.WATER_SPOUT_NAME) {
_this.waterSpout = entity;
}
});
if (_this.waterSpout) {
_this.waterSpoutPosition = Entities.getEntityProperties(_this.waterSpout, "position").position;
_this.waterSpoutRotation = Entities.getEntityProperties(_this.waterSpout, "rotation").rotation;
_this.createWaterEffect(); _this.createWaterEffect();
}
}, 3000);
}, },