mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 23:34:09 +02:00
update after updating models
This commit is contained in:
parent
9d49843114
commit
ca0aad7d3b
2 changed files with 380 additions and 283 deletions
|
@ -12,305 +12,402 @@
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var ARROW_MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/arrow.fbx";
|
var ZERO_VEC = {
|
||||||
var ARROW_COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/arrow_collision_hull.obj";
|
x: 0,
|
||||||
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js');
|
y: 0,
|
||||||
var ARROW_OFFSET = 0.25;
|
z: 0
|
||||||
var ARROW_FORCE = 1.25;
|
};
|
||||||
var ARROW_DIMENSIONS = {
|
var LINE_ENTITY_DIMENSIONS = {
|
||||||
x: 0.08,
|
x: 1000,
|
||||||
y: 0.02,
|
y: 1000,
|
||||||
z: 0.08
|
z: 1000
|
||||||
};
|
};
|
||||||
var ARROW_GRAVITY = {
|
|
||||||
x: 0,
|
|
||||||
y: -9.8,
|
|
||||||
z: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
var TOP_NOTCH_OFFSET = 0.5;
|
|
||||||
var BOTTOM_NOTCH_OFFSET = 0.5;
|
|
||||||
|
|
||||||
var LINE_DIMENSIONS = {
|
|
||||||
x: 5,
|
|
||||||
y: 5,
|
|
||||||
z: 5
|
|
||||||
};
|
|
||||||
|
|
||||||
var DRAW_STRING_THRESHOLD = 0.80;
|
|
||||||
|
|
||||||
var _this;
|
|
||||||
|
|
||||||
function Bow() {
|
|
||||||
_this = this;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create bow
|
|
||||||
// on pickup, wait for other hand to start trigger pull
|
|
||||||
// then create strings that start at top and bottom of bow
|
|
||||||
// extend them to the other hand position
|
|
||||||
// on trigger release,
|
|
||||||
// create arrow
|
|
||||||
// shoot arrow with velocity relative to distance between hand position and bow
|
|
||||||
// delete lines
|
|
||||||
|
|
||||||
Bow.prototype = {
|
|
||||||
isGrabbed: false,
|
|
||||||
stringDrawn: false,
|
|
||||||
hasArrow: false,
|
|
||||||
stringData: {
|
|
||||||
currentColor: {
|
|
||||||
red: 0,
|
|
||||||
green: 255,
|
|
||||||
blue: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
preload: function(entityID) {
|
|
||||||
this.entityID = entityID;
|
|
||||||
},
|
|
||||||
|
|
||||||
setLeftHand: function() {
|
|
||||||
if (this.isGrabbed === true) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.hand = 'left';
|
|
||||||
},
|
|
||||||
|
|
||||||
setRightHand: function() {
|
|
||||||
if (this.isGrabbed === true) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.hand = 'right';
|
|
||||||
},
|
|
||||||
|
|
||||||
drawStrings: function() {
|
|
||||||
|
|
||||||
this.updateStringPositions();
|
|
||||||
var lineVectors = this.getLocalLineVectors();
|
|
||||||
|
|
||||||
Entities.editEntity(this.topString, {
|
|
||||||
linePoints: [{
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
z: 0
|
|
||||||
}, lineVectors[0]],
|
|
||||||
lineWidth: 5,
|
|
||||||
color: this.stringData.currentColor
|
|
||||||
});
|
|
||||||
|
|
||||||
Entities.editEntity(this.bottomString, {
|
|
||||||
linePoints: [{
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
z: 0
|
|
||||||
}, lineVectors[1]],
|
|
||||||
lineWidth: 5,
|
|
||||||
color: this.stringData.currentColor
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
createStrings: function() {
|
|
||||||
this.createTopString();
|
|
||||||
this.createBottomString();
|
|
||||||
},
|
|
||||||
|
|
||||||
deleteStrings: function() {
|
|
||||||
Entities.deleteEntity(this.topString);
|
|
||||||
Entities.deleteEntity(this.bottomString);
|
|
||||||
},
|
|
||||||
|
|
||||||
createTopString: function() {
|
|
||||||
var stringProperties = {
|
|
||||||
type: 'Line',
|
|
||||||
position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET),
|
|
||||||
dimensions: LINE_DIMENSIONS
|
|
||||||
};
|
|
||||||
|
|
||||||
this.topString = Entities.addEntity(stringProperties);
|
|
||||||
},
|
|
||||||
|
|
||||||
createBottomString: function() {
|
|
||||||
var stringProperties = {
|
|
||||||
type: 'Line',
|
|
||||||
position: Vec3.sum(this.bowProperties.position, BOTTOM_NOTCH_OFFSET),
|
|
||||||
dimensions: LINE_DIMENSIONS
|
|
||||||
};
|
|
||||||
|
|
||||||
this.bottomString = Entities.addEntity(stringProperties);
|
|
||||||
},
|
|
||||||
|
|
||||||
updateStringPositions: function() {
|
|
||||||
|
|
||||||
var upVector = Quat.getFront(this.bowProperties.rotation);
|
|
||||||
var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET);
|
|
||||||
var downVector = Vec3.multiply(-1, Quat.getFront(this.bowProperties.rotation));
|
|
||||||
var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET);
|
|
||||||
|
|
||||||
this.topStringPosition = Vec3.sum(this.bowProperties.position, upOffset);
|
|
||||||
this.bottomStringPosition = Vec3.sum(this.bowProperties.position, downOffset);
|
|
||||||
|
|
||||||
Entities.editEntity(this.topString, {
|
|
||||||
position: this.topStringPosition
|
|
||||||
});
|
|
||||||
Entities.editEntity(this.bottomString, {
|
|
||||||
position: this.bottomStringPosition
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
},
|
var ARROW_MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/arrow_good.fbx";
|
||||||
|
var ARROW_COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/arrow_good_collision_hull.obj";
|
||||||
|
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js');
|
||||||
|
var ARROW_OFFSET = 0.25;
|
||||||
|
var ARROW_FORCE = 1.25;
|
||||||
|
var ARROW_DIMENSIONS = {
|
||||||
|
x: 0.01,
|
||||||
|
y: 0.01,
|
||||||
|
z: 0.08
|
||||||
|
};
|
||||||
|
var ARROW_GRAVITY = {
|
||||||
|
x: 0,
|
||||||
|
y: -9.8,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
|
||||||
startNearGrab: function() {
|
var TOP_NOTCH_OFFSET = 0.5;
|
||||||
if (this.isGrabbed === true) {
|
var BOTTOM_NOTCH_OFFSET = 0.5;
|
||||||
return false;
|
|
||||||
}
|
var LINE_DIMENSIONS = {
|
||||||
this.isGrabbed = true;
|
x: 5,
|
||||||
this.initialHand = this.hand;
|
y: 5,
|
||||||
Entities.editEntity(this.entityID, {
|
z: 5
|
||||||
userData: JSON.stringify({
|
};
|
||||||
grabbableKey: {
|
|
||||||
turnOffOtherHand: true,
|
var DRAW_STRING_THRESHOLD = 0.80;
|
||||||
turnOffOppositeBeam:true
|
|
||||||
|
var TARGET_LINE_LENGTH = 0.3;
|
||||||
|
|
||||||
|
var _this;
|
||||||
|
|
||||||
|
function Bow() {
|
||||||
|
_this = this;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create bow
|
||||||
|
// on pickup, wait for other hand to start trigger pull
|
||||||
|
// then create strings that start at top and bottom of bow
|
||||||
|
// extend them to the other hand position
|
||||||
|
// on trigger release,
|
||||||
|
// create arrow
|
||||||
|
// shoot arrow with velocity relative to distance between hand position and bow
|
||||||
|
// delete lines
|
||||||
|
|
||||||
|
Bow.prototype = {
|
||||||
|
isGrabbed: false,
|
||||||
|
stringDrawn: false,
|
||||||
|
hasArrow: false,
|
||||||
|
stringData: {
|
||||||
|
currentColor: {
|
||||||
|
red: 0,
|
||||||
|
green: 255,
|
||||||
|
blue: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
preload: function(entityID) {
|
||||||
|
this.entityID = entityID;
|
||||||
|
},
|
||||||
|
|
||||||
|
setLeftHand: function() {
|
||||||
|
if (this.isGrabbed === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.hand = 'left';
|
||||||
|
},
|
||||||
|
|
||||||
|
setRightHand: function() {
|
||||||
|
if (this.isGrabbed === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.hand = 'right';
|
||||||
|
},
|
||||||
|
|
||||||
|
drawStrings: function() {
|
||||||
|
|
||||||
|
this.updateStringPositions();
|
||||||
|
var lineVectors = this.getLocalLineVectors();
|
||||||
|
|
||||||
|
Entities.editEntity(this.topString, {
|
||||||
|
linePoints: [{
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
}, lineVectors[0]],
|
||||||
|
lineWidth: 5,
|
||||||
|
color: this.stringData.currentColor
|
||||||
|
});
|
||||||
|
|
||||||
|
Entities.editEntity(this.bottomString, {
|
||||||
|
linePoints: [{
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
}, lineVectors[1]],
|
||||||
|
lineWidth: 5,
|
||||||
|
color: this.stringData.currentColor
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
createStrings: function() {
|
||||||
|
this.createTopString();
|
||||||
|
this.createBottomString();
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteStrings: function() {
|
||||||
|
Entities.deleteEntity(this.topString);
|
||||||
|
Entities.deleteEntity(this.bottomString);
|
||||||
|
},
|
||||||
|
|
||||||
|
createTopString: function() {
|
||||||
|
var stringProperties = {
|
||||||
|
type: 'Line',
|
||||||
|
position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET),
|
||||||
|
dimensions: LINE_DIMENSIONS
|
||||||
|
};
|
||||||
|
|
||||||
|
this.topString = Entities.addEntity(stringProperties);
|
||||||
|
},
|
||||||
|
|
||||||
|
createBottomString: function() {
|
||||||
|
var stringProperties = {
|
||||||
|
type: 'Line',
|
||||||
|
position: Vec3.sum(this.bowProperties.position, BOTTOM_NOTCH_OFFSET),
|
||||||
|
dimensions: LINE_DIMENSIONS
|
||||||
|
};
|
||||||
|
|
||||||
|
this.bottomString = Entities.addEntity(stringProperties);
|
||||||
|
},
|
||||||
|
|
||||||
|
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));
|
||||||
|
var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET);
|
||||||
|
|
||||||
|
this.topStringPosition = Vec3.sum(this.bowProperties.position, upOffset);
|
||||||
|
this.bottomStringPosition = Vec3.sum(this.bowProperties.position, downOffset);
|
||||||
|
|
||||||
|
Entities.editEntity(this.topString, {
|
||||||
|
position: this.topStringPosition
|
||||||
|
});
|
||||||
|
Entities.editEntity(this.bottomString, {
|
||||||
|
position: this.bottomStringPosition
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
startNearGrab: function() {
|
||||||
|
if (this.isGrabbed === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.isGrabbed = true;
|
||||||
|
this.initialHand = this.hand;
|
||||||
|
Entities.editEntity(this.entityID, {
|
||||||
|
userData: JSON.stringify({
|
||||||
|
grabbableKey: {
|
||||||
|
turnOffOtherHand: true,
|
||||||
|
turnOffOppositeBeam: true
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
continueNearGrab: function() {
|
||||||
|
this.bowProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
|
||||||
|
this.checkStringHand();
|
||||||
|
this.createTargetLine();
|
||||||
|
},
|
||||||
|
|
||||||
|
releaseGrab: function() {
|
||||||
|
if (this.isGrabbed === true && this.hand === this.initialHand) {
|
||||||
|
this.isGrabbed = false;
|
||||||
|
this.stringDrawn = false;
|
||||||
|
this.deleteStrings();
|
||||||
|
this.hasArrow = false;
|
||||||
|
Entities.editEntity(this.entityID, {
|
||||||
|
userData: JSON.stringify({
|
||||||
|
grabbableKey: {
|
||||||
|
turnOffOtherHand: false,
|
||||||
|
turnOffOppositeBeam: true
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
checkStringHand: function() {
|
||||||
|
//invert the hands because our string will be held with the opposite hand of the first one we pick up the bow with
|
||||||
|
if (this.initialHand === 'left') {
|
||||||
|
this.getStringHandPosition = MyAvatar.getRightPalmPosition;
|
||||||
|
this.getStringHandRotation = MyAvatar.getRightPalmRotation;
|
||||||
|
this.stringTriggerAction = Controller.findAction("RIGHT_HAND_CLICK");
|
||||||
|
} else if (this.initialHand === 'right') {
|
||||||
|
this.getStringHandPosition = MyAvatar.getLeftPalmPosition;
|
||||||
|
this.getStringHandRotation = MyAvatar.getLeftPalmRotation;
|
||||||
|
this.stringTriggerAction = Controller.findAction("LEFT_HAND_CLICK");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.triggerValue = Controller.getActionValue(this.stringTriggerAction);
|
||||||
|
|
||||||
|
if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
||||||
|
// print('TRIGGER 1');
|
||||||
|
//let it fly
|
||||||
|
this.stringDrawn = false;
|
||||||
|
this.deleteStrings();
|
||||||
|
this.hasArrow = false;
|
||||||
|
this.releaseArrow();
|
||||||
|
|
||||||
|
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
||||||
|
//print('TRIGGER 2');
|
||||||
|
//update
|
||||||
|
this.stringData.handPosition = this.getStringHandPosition();
|
||||||
|
this.stringData.handRotation = this.getStringHandRotation();
|
||||||
|
this.drawStrings();
|
||||||
|
this.updateArrowPosition();
|
||||||
|
|
||||||
|
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === false) {
|
||||||
|
//print('TRIGGER 3');
|
||||||
|
//create
|
||||||
|
this.stringDrawn = true;
|
||||||
|
this.createStrings();
|
||||||
|
this.stringData.handPosition = this.getStringHandPosition();
|
||||||
|
this.stringData.handRotation = this.getStringHandRotation();
|
||||||
|
if (this.hasArrow === false) {
|
||||||
|
this.createArrow();
|
||||||
|
this.hasArrow = true;
|
||||||
|
}
|
||||||
|
this.drawStrings();
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
continueNearGrab: function() {
|
},
|
||||||
this.bowProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
|
|
||||||
this.checkStringHand();
|
|
||||||
},
|
|
||||||
|
|
||||||
releaseGrab: function() {
|
getArrowPosition: function() {
|
||||||
if (this.isGrabbed === true && this.hand === this.initialHand) {
|
|
||||||
this.isGrabbed = false;
|
|
||||||
this.stringDrawn = false;
|
|
||||||
this.deleteStrings();
|
|
||||||
this.hasArrow = false;
|
|
||||||
Entities.editEntity(this.entityID, {
|
|
||||||
userData: JSON.stringify({
|
|
||||||
grabbableKey: {
|
|
||||||
turnOffOtherHand: false,
|
|
||||||
turnOffOppositeBeam:true
|
|
||||||
|
|
||||||
}
|
var arrowVector = Vec3.subtract(this.bowProperties.position, this.stringData.handPosition);
|
||||||
})
|
arrowVector = Vec3.normalize(arrowVector);
|
||||||
});
|
arrowVector = Vec3.multiply(arrowVector, ARROW_OFFSET);
|
||||||
}
|
var arrowPosition = Vec3.sum(this.stringData.handPosition, arrowVector);
|
||||||
},
|
return arrowPosition;
|
||||||
|
},
|
||||||
|
|
||||||
checkStringHand: function() {
|
updateArrowPosition: function() {
|
||||||
//invert the hands because our string will be held with the opposite hand of the first one we pick up the bow with
|
var arrowPosition = this.getArrowPosition();
|
||||||
if (this.initialHand === 'left') {
|
|
||||||
this.getStringHandPosition = MyAvatar.getRightPalmPosition;
|
|
||||||
this.getStringHandRotation = MyAvatar.getRightPalmRotation;
|
|
||||||
this.stringTriggerAction = Controller.findAction("RIGHT_HAND_CLICK");
|
|
||||||
} else if (this.initialHand === 'right') {
|
|
||||||
this.getStringHandPosition = MyAvatar.getLeftPalmPosition;
|
|
||||||
this.getStringHandRotation = MyAvatar.getLeftPalmRotation;
|
|
||||||
this.stringTriggerAction = Controller.findAction("LEFT_HAND_CLICK");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.triggerValue = Controller.getActionValue(this.stringTriggerAction);
|
var bowRotation = Quat.getFront(this.bowProperties.rotation);
|
||||||
|
|
||||||
if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
Entities.editEntity(this.arrow, {
|
||||||
// print('TRIGGER 1');
|
position: arrowPosition,
|
||||||
//let it fly
|
rotation: this.bowProperties.rotation
|
||||||
this.stringDrawn = false;
|
});
|
||||||
this.deleteStrings();
|
},
|
||||||
this.hasArrow = false;
|
createArrow: function() {
|
||||||
this.releaseArrow();
|
// print('CREATING ARROW');
|
||||||
|
var arrowProperties = {
|
||||||
|
name: 'Hifi-Arrow',
|
||||||
|
type: 'Model',
|
||||||
|
modelURL: ARROW_MODEL_URL,
|
||||||
|
dimensions: ARROW_DIMENSIONS,
|
||||||
|
position: this.getArrowPosition(),
|
||||||
|
rotation: this.bowProperties.rotation,
|
||||||
|
collisionsWillMove: false,
|
||||||
|
ignoreForCollisions: true,
|
||||||
|
script: ARROW_SCRIPT_URL,
|
||||||
|
lifetime: 40
|
||||||
|
};
|
||||||
|
|
||||||
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
this.arrow = Entities.addEntity(arrowProperties);
|
||||||
//print('TRIGGER 2');
|
},
|
||||||
//update
|
|
||||||
this.stringData.handPosition = this.getStringHandPosition();
|
|
||||||
this.stringData.handRotation = this.getStringHandRotation();
|
|
||||||
this.drawStrings();
|
|
||||||
this.updateArrowPosition();
|
|
||||||
|
|
||||||
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === false) {
|
createTargetLine: function() {
|
||||||
//print('TRIGGER 3');
|
|
||||||
//create
|
|
||||||
this.stringDrawn = true;
|
|
||||||
this.createStrings();
|
|
||||||
this.stringData.handPosition = this.getStringHandPosition();
|
|
||||||
this.stringData.handRotation = this.getStringHandRotation();
|
|
||||||
if (this.hasArrow === false) {
|
|
||||||
this.createArrow();
|
|
||||||
this.hasArrow = true;
|
|
||||||
}
|
|
||||||
this.drawStrings();
|
|
||||||
|
|
||||||
}
|
var bowRotation = this.bowProperties.rotation;
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
getArrowPosition: function() {
|
Entities.addEntity({
|
||||||
|
type: "Line",
|
||||||
|
name: "Debug Line",
|
||||||
|
dimensions: LINE_ENTITY_DIMENSIONS,
|
||||||
|
visible: true,
|
||||||
|
rotation: bowRotation,
|
||||||
|
position: this.bowProperties.position,
|
||||||
|
linePoints: [ZERO_VEC, Vec3.multiply(TARGET_LINE_LENGTH, Quat.getFront(this.bowProperties.rotation))],
|
||||||
|
color: {
|
||||||
|
red: 255,
|
||||||
|
green: 0,
|
||||||
|
blue: 255
|
||||||
|
},
|
||||||
|
lifetime: 0.1
|
||||||
|
});
|
||||||
|
|
||||||
var arrowVector = Vec3.subtract(this.bowProperties.position, this.stringData.handPosition);
|
Entities.addEntity({
|
||||||
arrowVector = Vec3.normalize(arrowVector);
|
type: "Line",
|
||||||
arrowVector = Vec3.multiply(arrowVector, ARROW_OFFSET);
|
name: "Debug Line",
|
||||||
var arrowPosition = Vec3.sum(this.stringData.handPosition, arrowVector);
|
dimensions: LINE_ENTITY_DIMENSIONS,
|
||||||
return arrowPosition;
|
visible: true,
|
||||||
},
|
// rotation: bowRotation,
|
||||||
|
position: this.bowProperties.position,
|
||||||
|
linePoints: [ZERO_VEC, Vec3.multiply(TARGET_LINE_LENGTH, {
|
||||||
|
x: 1,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
})],
|
||||||
|
color: {
|
||||||
|
red: 255,
|
||||||
|
green: 0,
|
||||||
|
blue: 0
|
||||||
|
},
|
||||||
|
lifetime: 0.1
|
||||||
|
});
|
||||||
|
|
||||||
updateArrowPosition: function() {
|
Entities.addEntity({
|
||||||
var arrowPosition = this.getArrowPosition();
|
type: "Line",
|
||||||
|
name: "Debug Line",
|
||||||
|
dimensions: LINE_ENTITY_DIMENSIONS,
|
||||||
|
visible: true,
|
||||||
|
// rotation: bowRotation,
|
||||||
|
position: this.bowProperties.position,
|
||||||
|
linePoints: [ZERO_VEC, Vec3.multiply(TARGET_LINE_LENGTH, {
|
||||||
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
z: 0
|
||||||
|
})],
|
||||||
|
color: {
|
||||||
|
red: 0,
|
||||||
|
green: 255,
|
||||||
|
blue: 0
|
||||||
|
},
|
||||||
|
lifetime: 0.1
|
||||||
|
});
|
||||||
|
|
||||||
var arrowRotation = Quat.getFront(this.bowProperties.rotation);
|
Entities.addEntity({
|
||||||
// print('ARROW POSITION:::' + JSON.stringify(arrowPosition));
|
type: "Line",
|
||||||
Entities.editEntity(this.arrow, {
|
name: "Debug Line",
|
||||||
position: arrowPosition,
|
dimensions: LINE_ENTITY_DIMENSIONS,
|
||||||
rotation: arrowRotation
|
visible: true,
|
||||||
});
|
// rotation:bowRotation,
|
||||||
},
|
position: this.bowProperties.position,
|
||||||
|
linePoints: [ZERO_VEC, Vec3.multiply(TARGET_LINE_LENGTH, {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 1
|
||||||
|
})],
|
||||||
|
color: {
|
||||||
|
red: 0,
|
||||||
|
green: 0,
|
||||||
|
blue: 255
|
||||||
|
},
|
||||||
|
lifetime: 0.1
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
createArrow: function() {
|
|
||||||
// print('CREATING ARROW');
|
|
||||||
var arrowProperties = {
|
|
||||||
name: 'Hifi-Arrow',
|
|
||||||
type: 'Model',
|
|
||||||
modelURL: ARROW_MODEL_URL,
|
|
||||||
dimensions: ARROW_DIMENSIONS,
|
|
||||||
position: this.getArrowPosition(),
|
|
||||||
rotation: this.bowProperties.rotation,
|
|
||||||
collisionsWillMove: false,
|
|
||||||
ignoreForCollisions: true,
|
|
||||||
script: ARROW_SCRIPT_URL,
|
|
||||||
lifetime: 40
|
|
||||||
};
|
|
||||||
|
|
||||||
this.arrow = Entities.addEntity(arrowProperties);
|
releaseArrow: function() {
|
||||||
},
|
|
||||||
|
|
||||||
releaseArrow: function() {
|
var forwardVec = Quat.getRight(Quat.multiply(this.bowProperties.rotation, Quat.fromPitchYawRollDegrees(0, 40, 0)));
|
||||||
|
forwardVec = Vec3.normalize(forwardVec);
|
||||||
|
var handDistanceAtRelease = Vec3.length(this.bowProperties.position, this.stringData.handPosition);
|
||||||
|
|
||||||
var forwardVec = Quat.getRight(Quat.multiply(this.bowProperties.rotation, Quat.fromPitchYawRollDegrees(0, 180, 0)));
|
forwardVec = Vec3.multiply(forwardVec, ARROW_FORCE);
|
||||||
forwardVec = Vec3.normalize(forwardVec);
|
|
||||||
var handDistanceAtRelease = Vec3.length(this.bowProperties.position, this.stringData.handPosition);
|
|
||||||
|
|
||||||
forwardVec = Vec3.multiply(forwardVec, ARROW_FORCE);
|
var arrowProperties = {
|
||||||
|
velocity: forwardVec,
|
||||||
|
collisionsWillMove: true,
|
||||||
|
gravity: ARROW_GRAVITY,
|
||||||
|
lifetime: 20
|
||||||
|
};
|
||||||
|
|
||||||
var arrowProperties = {
|
Entities.editEntity(this.arrow, arrowProperties);
|
||||||
velocity: forwardVec,
|
},
|
||||||
collisionsWillMove: true,
|
getLocalLineVectors: function() {
|
||||||
gravity: ARROW_GRAVITY,
|
var topVector = Vec3.subtract(this.stringData.handPosition, this.topStringPosition);
|
||||||
lifetime: 20
|
var bottomVector = Vec3.subtract(this.stringData.handPosition, this.bottomStringPosition);
|
||||||
};
|
return [topVector, bottomVector];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Entities.editEntity(this.arrow, arrowProperties);
|
return new Bow();
|
||||||
},
|
});
|
||||||
getLocalLineVectors: function() {
|
|
||||||
var topVector = Vec3.subtract(this.stringData.handPosition, this.topStringPosition);
|
|
||||||
var bottomVector = Vec3.subtract(this.stringData.handPosition, this.bottomStringPosition);
|
|
||||||
return [topVector, bottomVector];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return new Bow();
|
|
||||||
});
|
|
|
@ -13,12 +13,12 @@
|
||||||
|
|
||||||
var SCRIPT_URL = Script.resolvePath('bow.js');
|
var SCRIPT_URL = Script.resolvePath('bow.js');
|
||||||
|
|
||||||
var MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/bow.fbx";
|
var MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/bow_good.fbx";
|
||||||
var COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/bow_collision_hull.obj";
|
var COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/bow_good_collision_hull.obj";
|
||||||
var BOW_DIMENSIONS = {
|
var BOW_DIMENSIONS = {
|
||||||
x: 0.1,
|
x: 0.02,
|
||||||
y: 0.02,
|
y: 1,
|
||||||
z: 1
|
z: 0.1
|
||||||
};
|
};
|
||||||
|
|
||||||
var BOW_GRAVITY = {
|
var BOW_GRAVITY = {
|
||||||
|
@ -26,7 +26,7 @@ var BOW_GRAVITY = {
|
||||||
y: 0,
|
y: 0,
|
||||||
z: 0
|
z: 0
|
||||||
}
|
}
|
||||||
var BOW_ROTATION = Quat.fromPitchYawRollDegrees(90, 180, 0);
|
// var BOW_ROTATION = Quat.fromPitchYawRollDegrees(90, 180, 0);
|
||||||
|
|
||||||
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
|
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
|
||||||
x: 0,
|
x: 0,
|
||||||
|
@ -39,7 +39,7 @@ var bow = Entities.addEntity({
|
||||||
type: "Model",
|
type: "Model",
|
||||||
modelURL: MODEL_URL,
|
modelURL: MODEL_URL,
|
||||||
position: center,
|
position: center,
|
||||||
rotation: BOW_ROTATION,
|
// rotation: BOW_ROTATION,
|
||||||
dimensions: BOW_DIMENSIONS,
|
dimensions: BOW_DIMENSIONS,
|
||||||
collisionsWillMove: true,
|
collisionsWillMove: true,
|
||||||
gravity: BOW_GRAVITY,
|
gravity: BOW_GRAVITY,
|
||||||
|
|
Loading…
Reference in a new issue