make bow equippable and change it so you dont have to load arrows

This commit is contained in:
James B. Pollack 2015-11-18 15:33:47 -08:00
parent ac336af9b5
commit 328950065f
7 changed files with 182 additions and 443 deletions

View file

@ -155,14 +155,14 @@ spawnGround();
spawnBoxes();
function cleanup() {
Entities.deleteEntity(ground);
boxes.forEach(function(box) {
Entities.deleteEntity(box);
});
dustSystems.forEach(function(dustEffect) {
Entities.deleteEntity(dustEffect);
})
}
// function cleanup() {
// Entities.deleteEntity(ground);
// boxes.forEach(function(box) {
// Entities.deleteEntity(box);
// });
// dustSystems.forEach(function(dustEffect) {
// Entities.deleteEntity(dustEffect);
// })
// }
Script.scriptEnding.connect(cleanup);
// Script.scriptEnding.connect(cleanup);

View file

@ -1,241 +0,0 @@
//
// arrow.js
//
// This script attaches to an arrow to make it stop and stick when it hits something. Could use this to make it a fire arrow or really give any kind of property to itself or the entity it hits.
//
// Created by James B. Pollack @imgntn on 10/19/2015
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
Script.include("../../libraries/utils.js");
var NOTCH_DETECTOR_SEARCH_RADIUS = 0.25;
var FIRE_DETECTOR_SEARCH_RADIUS = 0.25;
var _this;
function Arrow() {
_this = this;
return;
}
Arrow.prototype = {
stickOnCollision: false,
notched: false,
isBurning: false,
fire: null,
preload: function(entityID) {
this.entityID = entityID;
},
releaseGrab: function() {
if (this.fire !== null) {
this.fire = null;
this.isBurning = false;
Entities.deleteEntity(this.fire);
}
},
continueNearGrab: function() {
this.currentProperties = Entities.getEntityProperties(this.entityID, "position");
if(this.notched===true){
return;
}
if (this.isBurning !== true) {
this.searchForFires();
} else {
this.updateFirePosition();
}
if (this.notched !== true) {
this.searchForNotchDetectors();
}
},
searchForNotchDetectors: function() {
if (this.notched === true) {
return
};
var ids = Entities.findEntities(this.currentProperties.position, NOTCH_DETECTOR_SEARCH_RADIUS);
var i, properties;
for (i = 0; i < ids.length; i++) {
id = ids[i];
properties = Entities.getEntityProperties(id, 'name');
if (properties.name === "Hifi-NotchDetector") {
print('NEAR THE NOTCH!!!')
this.notched = true;
this.tellBowArrowIsNotched(this.getBowID(id));
}
}
},
searchForFires: function() {
print('SEARCHING FOR FIRES!')
if (this.notched === true) {
return
};
if (this.isBurning === true) {
return
};
var ids = Entities.findEntities(this.currentProperties.position, FIRE_DETECTOR_SEARCH_RADIUS);
var i, properties;
for (i = 0; i < ids.length; i++) {
id = ids[i];
properties = Entities.getEntityProperties(id, 'name');
if (properties.name === "Hifi-Arrow-Fire-Source") {
print('NEAR A FIRE SOURCE!!!');
this.isBurning = true;
this.createFireParticleSystem();
}
}
},
updateFirePosition: function() {
print('updating fire position' + this.fire)
Entities.editEntity(this.fire, {
position: this.currentProperties.position
})
},
createFireParticleSystem: function() {
print('CREATING FIRE PARTICLE SYSTEM')
var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0);
var animationSettings = JSON.stringify({
fps: 30,
running: true,
loop: true,
firstFrame: 1,
lastFrame: 10000
});
this.fire = Entities.addEntity({
type: "ParticleEffect",
name: "Hifi-Arrow-Fire-Source",
animationSettings: animationSettings,
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
emitRate: 100,
position: this.currentProperties.position,
colorStart: {
red: 70,
green: 70,
blue: 137
},
color: {
red: 200,
green: 99,
blue: 42
},
colorFinish: {
red: 255,
green: 99,
blue: 32
},
radiusSpread: 0.01,
radiusStart: 0.02,
radiusEnd: 0.001,
particleRadius: 0.15,
radiusFinish: 0.0,
emitOrientation: myOrientation,
emitSpeed: 0.3,
speedSpread: 0.1,
alphaStart: 0.05,
alpha: 0.1,
alphaFinish: 0.05,
emitDimensions: {
x: 1,
y: 1,
z: 0.1
},
polarFinish: 0.1,
emitAcceleration: {
x: 0.0,
y: 0.0,
z: 0.0
},
accelerationSpread: {
x: 0.1,
y: 0.01,
z: 0.1
},
lifespan: 1
});
},
getBowID: function(notchDetectorID) {
var properties = Entities.getEntityProperties(notchDetectorID, "userData");
var userData = JSON.parse(properties.userData);
if (userData.hasOwnProperty('hifiBowKey')) {
return userData.hifiBowKey.bowID;
}
},
getActionID: function() {
var properties = Entities.getEntityProperties(this.entityID, "userData");
var userData = JSON.parse(properties.userData);
if (userData.hasOwnProperty('hifiHoldActionKey')) {
return userData.hifiHoldActionKey.holdActionID;
}
},
disableGrab: function() {
var actionID = this.getActionID();
var success = Entities.deleteAction(this.entityID, actionID);
},
tellBowArrowIsNotched: function(bowID) {
this.disableGrab();
setEntityCustomData('grabbableKey', this.entityID, {
grabbable: false,
invertSolidWhileHeld: true
});
Entities.editEntity(this.entityID, {
collisionsWillMove: true,
ignoreForCollisions: false,
gravity:{
x:0,
y:-5.8,
z:0
}
})
setEntityCustomData('hifiBowKey', bowID, {
hasArrowNotched: true,
arrowIsBurning: this.isBurning,
arrowID: this.entityID
});
if (this.isBurning === true) {
this.isBurning = false;
this.fire = null;
Entities.deleteEntity(this.fire);
}
},
}
function deleteEntity(entityID) {
if (entityID === _this.entityID) {
if (_this.isBurning === true) {
Entities.deleteEntity(_this.fire);
}
}
}
Entities.deletingEntity.connect(deleteEntity);
return new Arrow;
})

View file

@ -50,10 +50,21 @@
var ARROW_TIP_OFFSET = 0.32;
var ARROW_GRAVITY = {
x: 0,
y: -5.8,
y: -4.8,
z: 0
};
var ARROW_MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow.fbx";
var ARROW_COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow_collision_hull.obj";
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js');
var ARROW_DIMENSIONS = {
x: 0.02,
y: 0.02,
z: 0.64
};
var TOP_NOTCH_OFFSET = 0.6;
var BOTTOM_NOTCH_OFFSET = 0.6;
@ -84,10 +95,18 @@
var SHOT_SCALE = {
min1: 0,
max1: 0.6,
min2: 3,
max2: 15
min2: 1,
max2: 10
}
var BOW_SPATIAL_KEY = {
relativePosition: {
x: 0,
y: 0.06,
z: 0.11
},
relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90)
}
var _this;
@ -105,12 +124,13 @@
Bow.prototype = {
isGrabbed: false,
stringDrawn: false,
aiming: false,
arrowTipPosition: null,
preNotchString: null,
hasArrowNotched: false,
notchDetector: null,
arrow: null,
arrowIsBurning:false,
arrowIsBurning: false,
stringData: {
currentColor: {
red: 255,
@ -134,6 +154,22 @@
unload: function() {
Script.update.disconnect(this.updateArrowTrackers);
while (this.arrowTrackers.length > 0) {
var tracker = this.arrowTrackers.pop();
tracker.childEntities.forEach(function(child) {
Entities.deleteEntity(child);
})
tracker.childParticleSystems.forEach(function(child) {
Entities.deleteEntity(child);
})
Entities.deleteEntity(tracker.arrowID);
}
this.deleteStrings();
Entities.deleteEntity(this.notchDetector);
Entities.deleteEntity(this.preNotchString);
Entities.deleteEntity(this.arrow);
Script.clearInterval(physicalArrowInterval);
},
setLeftHand: function() {
@ -159,7 +195,8 @@
setEntityCustomData('grabbableKey', this.entityID, {
turnOffOtherHand: true,
invertSolidWhileHeld: true
invertSolidWhileHeld: true,
spatialKey: BOW_SPATIAL_KEY
});
},
@ -177,40 +214,30 @@
this.updateNotchDetectorPosition();
//check to see if an arrow has notched itself in our notch detector
var userData = JSON.parse(this.bowProperties.userData);
if (userData.hasOwnProperty('hifiBowKey')) {
if (this.hasArrowNotched === false && userData.hifiBowKey.arrowID !== null) {
//notch the arrow
print('NOTCHING IT!')
this.playArrowNotchSound();
this.playStringPullSound();
this.hasArrowNotched = userData.hifiBowKey.hasArrowNotched;
this.arrow = userData.hifiBowKey.arrowID;
this.arrowIsBurning = userData.hifiBowKey.arrowIsBurning;
setEntityCustomData('grabbableKey', this.entityID, {
turnOffOtherHand: true,
invertSolidWhileHeld: true
});
}
if (this.hasArrowNotched === false) {
this.playArrowNotchSound();
this.playStringPullSound();
this.hasArrowNotched = true
this.arrow = this.createArrow();
print('NOTCH ARROW' + this.arrow);
this.arrowIsBurning = false
setEntityCustomData('grabbableKey', this.entityID, {
turnOffOtherHand: true,
invertSolidWhileHeld: true,
spatialKey: BOW_SPATIAL_KEY
});
}
//this.arrow
//this.hasArrowNotched
//create a string across the bow when we pick it up
if (this.preNotchString === null) {
print('CREATE PRE NOTCH STRING')
this.createPreNotchString();
}
if (this.preNotchString !== null && this.hasArrowNotched === false) {
// print('DRAW PRE NOTCH STRING')
if (this.preNotchString !== null && this.aiming === false) {
// print('DRAW PRE NOTCH STRING')
this.drawPreNotchStrings();
this.updateArrowAttachedToBow();
}
// create the notch detector that arrows will look for
@ -220,16 +247,17 @@
//if we have an arrow notched, then draw some new strings
if (this.hasArrowNotched === true) {
if (this.preNotchString !== null) {
// print('MAKE PRE NOTCH INVISIBLE')
if (this.aiming === true) {
Entities.editEntity(this.preNotchString, {
visible: false
});
})
} else {
Entities.editEntity(this.preNotchString, {
visible: true
})
}
// print('CHECK STRING HAND')
//only test for strings now that an arrow is notched
this.checkStringHand();
} else {
@ -240,23 +268,48 @@
},
releaseGrab: function() {
print('RELEASE GRAB EVENT')
if (this.isGrabbed === true && this.hand === this.initialHand) {
this.isGrabbed = false;
this.stringDrawn = false;
this.deleteStrings();
setEntityCustomData('grabbableKey', this.entityID, {
turnOffOtherHand: false,
invertSolidWhileHeld: true
invertSolidWhileHeld: true,
spatialKey: BOW_SPATIAL_KEY
});
Entities.deleteEntity(this.notchDetector);
Entities.deleteEntity(this.preNotchString);
Entities.deleteEntity(this.arrow);
this.aiming = false;
this.notchDetector = null;
this.hasArrowNotched = false;
this.preNotchString = null;
}
},
createArrow: function() {
var arrow = Entities.addEntity({
name: 'Hifi-Arrow',
type: 'Model',
modelURL: ARROW_MODEL_URL,
shapeType: 'compound',
compoundShapeURL: ARROW_COLLISION_HULL_URL,
dimensions: ARROW_DIMENSIONS,
position: this.bowProperties.position,
script: ARROW_SCRIPT_URL,
collisionsWillMove: false,
ignoreForCollisions: true,
collisionSoundURL: 'http://hifi-content.s3.amazonaws.com/bow_and_arrow/sounds/Arrow_impact1.L.wav',
gravity: ARROW_GRAVITY,
linearDamping: 0.01
});
return arrow
},
createStrings: function() {
this.createTopString();
this.createBottomString();
@ -264,6 +317,7 @@
createTopString: function() {
var stringProperties = {
name: 'Hifi-Bow-Top-String',
type: 'Line',
position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET),
dimensions: LINE_DIMENSIONS,
@ -281,6 +335,7 @@
createBottomString: function() {
var stringProperties = {
name: 'Hifi-Bow-Bottom-String',
type: 'Line',
position: Vec3.sum(this.bowProperties.position, BOTTOM_NOTCH_OFFSET),
dimensions: LINE_DIMENSIONS,
@ -302,7 +357,6 @@
},
updateStringPositions: function() {
var upVector = Quat.getUp(this.bowProperties.rotation);
var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET);
var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation));
@ -313,7 +367,6 @@
this.topStringPosition = Vec3.sum(topStringPosition, backOffset);
var bottomStringPosition = Vec3.sum(this.bowProperties.position, downOffset);
this.bottomStringPosition = Vec3.sum(bottomStringPosition, backOffset);
Entities.editEntity(this.topString, {
position: this.topStringPosition
});
@ -321,7 +374,6 @@
Entities.editEntity(this.bottomString, {
position: this.bottomStringPosition
});
Entities.editEntity(this.preNotchString, {
position: this.topStringPosition
});
@ -355,20 +407,18 @@
},
getLocalLineVectors: function() {
var topVector = Vec3.subtract(this.stringData.handPosition, this.topStringPosition);
var bottomVector = Vec3.subtract(this.stringData.handPosition, this.bottomStringPosition);
var topVector = Vec3.subtract(this.arrowRearPosition, this.topStringPosition);
var bottomVector = Vec3.subtract(this.arrowRearPosition, this.bottomStringPosition);
return [topVector, bottomVector];
},
createPreNotchString: function() {
var stringProperties = {
type: 'Line',
position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET),
dimensions: LINE_DIMENSIONS,
visible: true,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
@ -380,13 +430,11 @@
},
drawPreNotchStrings: function() {
this.updateStringPositions();
var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation));
var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET * 2);
Entities.editEntity(this.preNotchString, {
linePoints: [{
x: 0,
@ -424,13 +472,14 @@
if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
// firing the arrow
print('HIT RELEASE LOOP IN CHECK')
// print('HIT RELEASE LOOP IN CHECK')
this.releaseArrow();
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
print('HIT CONTINUE LOOP IN CHECK')
// print('HIT CONTINUE LOOP IN CHECK')
this.aiming = true;
//continuing to aim the arrow
this.stringData.handPosition = this.getStringHandPosition();
this.stringData.handRotation = this.getStringHandRotation();
@ -440,8 +489,8 @@
this.updateArrowPositionInNotch();
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === false) {
print('HIT START LOOP IN CHECK')
//the first time aiming the arrow
// print('HIT START LOOP IN CHECK')
//the first time aiming the arrow
this.stringDrawn = true;
this.createStrings();
var arrowTracker = this.createArrowTracker(this.arrow);
@ -465,6 +514,14 @@
this.arrowTipPosition = arrowTipPosition;
return arrowTipPosition;
},
setArrowRearPosition: function(arrowPosition, arrowRotation) {
var frontVector = Quat.getFront(arrowRotation);
var frontOffset = Vec3.multiply(frontVector, -ARROW_TIP_OFFSET);
var arrowTipPosition = Vec3.sum(arrowPosition, frontOffset);
this.arrowRearPosition = arrowTipPosition;
return arrowTipPosition;
},
getArrowPosition: function() {
var arrowVector = Vec3.subtract(this.stringData.handPosition, this.stringData.grabHandPosition);
@ -474,6 +531,13 @@
return arrowPosition;
},
updateArrowAttachedToBow: function() {
Entities.editEntity(this.arrow, {
position: this.notchDetectorPosition,
rotation: this.bowProperties.rotation
})
},
updateArrowPositionInNotch: function() {
//move it backwards
var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition);
@ -491,7 +555,8 @@
var finalArrowPosition = Vec3.sum(arrowPosition, pushForwardOffset);
var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch);
// this.setArrowTipPosition(finalArrowPosition, arrowRotation);
this.setArrowTipPosition(finalArrowPosition, arrowRotation);
this.setArrowRearPosition(finalArrowPosition, arrowRotation);
Entities.editEntity(this.arrow, {
position: finalArrowPosition,
rotation: arrowRotation
@ -514,25 +579,23 @@
var arrowForce = this.scaleArrowShotStrength(pullBackDistance);
print('ARROW FORCE::' + arrowForce);
handToNotch = Vec3.normalize(handToNotch)
var forwardVec=handToNotch;
// var forwardVec = Vec3.multiply(handToNotch, arrowForce);
// var forwardVec = handToNotch;
var forwardVec = Vec3.multiply(handToNotch, arrowForce);
var arrowProperties = {
// rotation: arrowRotation,
velocity: forwardVec
// rotation: arrowRotation,
velocity: forwardVec,
};
this.playShootArrowSound();
Entities.editEntity(this.arrow, arrowProperties);
setEntityCustomData('hifiBowKey', this.entityID, {
hasArrowNotched: false,
arrowID: null
});
Entities.editEntity(this.arrow, arrowProperties);
var arrowStore = this.arrow;
this.arrow = null;
this.hasArrowNotched = false;
this.aiming = false;
Entities.editEntity(this.preNotchString, {
visible: true
@ -543,37 +606,25 @@
//set an itnerval to heck how far the arrow is from the bow before adding gravity, etc. if we add this too soon, the arrow collides with the bow. hence, this function
// this.physicalArrowInterval = Script.setInterval(function() {
// print('in physical interval')
// var arrowProps = Entities.getEntityProperties(arrowStore, "position");
// var bowProps = Entities.getEntityProperties(_this.entityID, "position");
// var arrowPosition = arrowProps.position;
// var bowPosition = bowProps.position;
var physicalArrowInterval = Script.setInterval(function() {
print('in physical interval')
var arrowProps = Entities.getEntityProperties(arrowStore, "position");
var bowProps = Entities.getEntityProperties(_this.entityID, "position");
var arrowPosition = arrowProps.position;
var bowPosition = bowProps.position;
// var length = Vec3.distance(arrowPosition, bowPosition);
// print('LENGTH:::' + length);
// if (length > 2) {
// print('make arrow physical' + arrowStore)
// Entities.editEntity(arrowStore, {
// ignoreForCollisions: false,
// collisionsWillMove: true,
// gravity: ARROW_GRAVITY
// });
// print('after make physical' + arrowStore)
// var arrowProps = Entities.getEntityProperties(arrowStore)
// print('arrowprops-collisions::' + arrowProps.collisionsWillMove);
// print('arrowprops-graviy' + JSON.stringify(arrowProps.gravity));
// Script.setTimeout(function() {
// print('in timeout :: ' + arrowStore)
// var arrowProps = Entities.getEntityProperties(arrowStore)
// print('arrowprops-gravity2' + JSON.stringify(arrowProps.gravity));
// print('ARROW USER DATA::' + arrowProps.userData)
// }, 1000)
// Script.clearInterval(_this.physicalArrowInterval)
// }
// }, 10)
var length = Vec3.distance(arrowPosition, bowPosition);
print('LENGTH:::' + length);
if (length > 2) {
print('make arrow physical' + arrowStore)
Entities.editEntity(arrowStore, {
ignoreForCollisions: false,
collisionsWillMove: true
});
var arrowProps = Entities.getEntityProperties(arrowStore)
Script.clearInterval(physicalArrowInterval);
}
}, 5)
},
@ -608,12 +659,7 @@
red: 0,
green: 255,
blue: 0
},
userData: JSON.stringify({
hifiBowKey: {
bowID: this.entityID
}
})
}
};
this.notchDetector = Entities.addEntity(detectorProperties);
@ -699,7 +745,9 @@
y: 0.01,
z: 0.1
},
lifespan: 0.5
lifespan: 0.5,
ignoreForCollisions: true,
collisionsWillMove: false,
});
return fire;
@ -717,7 +765,7 @@
// whizzingSound: _t.playWhizzSound(),
//fireSound: _t.createFireSound(),
hasPlayedCollisionSound: false,
glowBox: _t.createGlowBox(),
glowBox: _t.createGlowBoxAsModel(),
fireParticleSystem: _t.createFireParticleSystem(),
childEntities: [],
childSounds: [],
@ -734,8 +782,8 @@
//have to reverse lookup the tracker by the arrow id to get access to the children
var tracker = getArrowTrackerByArrowID(entityA);
var bProps = Entities.getEntityProperties(entityB,"name")
print('ARROW COLLIDED WITH SOMETHING!'+bProps.name)
var bProps = Entities.getEntityProperties(entityB, "name")
print('ARROW COLLIDED WITH SOMETHING!' + bProps.name)
print('TRACKER IN COLLISION !' + tracker)
// _t.playArrowHitSound(collision.contactPoint);
//Vec3.print('penetration = ', collision.penetration);
@ -760,7 +808,8 @@
// print('UPDATING CHILDREN OF TRACKER:::' + this.childEntities.length);
var arrowProperties = Entities.getEntityProperties(this.arrowID, ["position", "rotation"]);
_t.setArrowTipPosition(arrowProperties.position, arrowProperties.rotation);
_t.setArrowRearPosition(arrowProperties.position, arrowProperties.rotation);
//update the positions
// this.soundEntities.forEach(function(injector) {
// var audioProperties = {
@ -779,7 +828,7 @@
this.childParticleSystems.forEach(function(child) {
Entities.editEntity(child, {
position: arrowProperties.position
position: _t.arrowTipPosition
})
})
@ -803,15 +852,22 @@
return injector
},
createGlowBoxAsModel: function() {
var modelURL = 'http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/glowBox.fbx';
var GLOW_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/glow.fbx';
var properties = {
name: 'Hifi-Arrow-Glow',
name: 'Hifi-Arrow-Glow-Model',
type: 'Model',
modelURL: modelURL,
modelURL: GLOW_MODEL_URL,
dimensions: ARROW_DIMENSIONS,
collisionsWillMove: false,
ignoreForCollisions: true,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
}
})
}
var glowBox = Entities.addEntity(properties);
return glowBox
},
createGlowBox: function() {
print('creating glow box')

View file

@ -1,74 +0,0 @@
//
// createArrow.js
//
// Created byJames Pollack @imgntn on 10/19/2015
// Copyright 2015 High Fidelity, Inc.
//
// This script creates a bow you can use to shoot an arrow.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var ARROW_MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow.fbx";
var ARROW_COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow_collision_hull.obj";
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js');
var ARROW_DIMENSIONS = {
x: 0.02,
y: 0.02,
z: 0.64
};
var ARROW_GRAVITY = {
x: 0,
y: 0,
z: 0
};
function cleanup() {
Entities.deleteEntity(arrow);
}
var arrow;
function createArrow(i) {
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
x: 0,
y: 0.5,
z: 0
}), Vec3.multiply(1.25*i, Quat.getFront(Camera.getOrientation())));
arrow = Entities.addEntity({
name: 'Hifi-Arrow',
type: 'Model',
modelURL: ARROW_MODEL_URL,
shapeType: 'compound',
compoundShapeURL: ARROW_COLLISION_HULL_URL,
dimensions: ARROW_DIMENSIONS,
position: center,
script: ARROW_SCRIPT_URL,
collisionsWillMove: true,
ignoreForCollisions: false,
collisionSoundURL:'http://hifi-content.s3.amazonaws.com/bow_and_arrow/sounds/Arrow_impact1.L.wav',
gravity: ARROW_GRAVITY,
linearDamping:0.01,
userData: JSON.stringify({
grabbableKey: {
invertSolidWhileHeld: true
}
})
});
}
var i;
for(i=1;i<6;i++){
createArrow(i);
}
Script.scriptEnding.connect(cleanup);

View file

@ -50,8 +50,8 @@ var bow = Entities.addEntity({
spatialKey: {
relativePosition: {
x: 0,
y: 0.1,
z: 0
y: 0.06,
z: 0.11
},
relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90)
}

View file

@ -1,2 +0,0 @@
Script.include("createBow.js");
Script.include("createArrow.js");

View file

@ -1,4 +1,4 @@
// arrowFieldSpawner.js
// fieldSpawner.js
// examples
//
// Created by James B. Pollack @imgntn on 11/16/2015
@ -95,12 +95,12 @@ spawnGround();
spawnBoxes();
function cleanup() {
Entities.deleteEntity(ground);
boxes.forEach(function(box) {
Entities.deleteEntity(box);
});
// function cleanup() {
// Entities.deleteEntity(ground);
// boxes.forEach(function(box) {
// Entities.deleteEntity(box);
// });
}
// }
Script.scriptEnding.connect(cleanup);
// Script.scriptEnding.connect(cleanup);