mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
through notching the arrow
This commit is contained in:
parent
68a4365fa5
commit
24a5cdc19e
5 changed files with 90 additions and 6 deletions
|
@ -613,6 +613,9 @@ function MyController(hand, triggerAction) {
|
|||
Entities.callEntityMethod(this.grabbedEntity, "setLeftHand");
|
||||
}
|
||||
Entities.callEntityMethod(this.grabbedEntity, "startNearGrab");
|
||||
setEntityCustomData('hifiHoldActionKey', this.grabbedEntity, {
|
||||
holdActionID: this.actionID
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -59,32 +59,48 @@
|
|||
// }
|
||||
|
||||
},
|
||||
|
||||
startNearGrab: function() {
|
||||
print('STARTING GRAB ON ARROW!!')
|
||||
},
|
||||
continueNearGrab: function() {
|
||||
this.currentProperties = Entities.getEntityProperties(this.entityID, "position");
|
||||
this.searchForNotchDetectors();
|
||||
},
|
||||
|
||||
searchForNotchDetectors: function() {
|
||||
if (this.notched === true) {
|
||||
return
|
||||
};
|
||||
print('SEARCHING FOR NOTCH DETECTOR');
|
||||
|
||||
var ids = Entities.findEntities(MyAvatar.position, NOTCH_DETECTOR_SEARCH_RADIUS);
|
||||
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") {
|
||||
this.tellBowArrowIsNotched(this.getBowID());
|
||||
print('NEAR THE NOTCH!!!')
|
||||
this.notched = true;
|
||||
this.tellBowArrowIsNotched(this.getBowID(id));
|
||||
this.disableGrab();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
getBowID: function() {
|
||||
var properties = Entities.getEntityProperties(notchDetector, "userData");
|
||||
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;
|
||||
}
|
||||
},
|
||||
|
||||
tellBowArrowIsNotched: function(bowID) {
|
||||
setEntityCustomData('hifiBowKey', bowID, {
|
||||
|
@ -94,9 +110,13 @@
|
|||
},
|
||||
|
||||
disableGrab: function() {
|
||||
print('ACTION ID IS::: ' + this.getActionID());
|
||||
Entities.deleteAction(this.entityID, this.getActionID());
|
||||
|
||||
setEntityCustomData('grabbableKey', this.entityID, {
|
||||
grabbable: false
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
checkIfBurning: function() {
|
||||
|
|
|
@ -519,7 +519,6 @@
|
|||
})
|
||||
};
|
||||
|
||||
|
||||
this.notchDetector = Entities.addEntity(detectorProperties);
|
||||
},
|
||||
|
||||
|
|
60
examples/toybox/bow/createArrow.js
Normal file
60
examples/toybox/bow/createArrow.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
//
|
||||
// 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
|
||||
};
|
||||
|
||||
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
}), Vec3.multiply(1.25, Quat.getFront(Camera.getOrientation())));
|
||||
|
||||
function cleanup() {
|
||||
Entities.deleteEntity(arrow);
|
||||
}
|
||||
|
||||
var arrow;
|
||||
|
||||
function createArrow() {
|
||||
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,
|
||||
gravity: ARROW_GRAVITY
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
createArrow();
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
2
examples/toybox/bow/createBowAndArrow.js
Normal file
2
examples/toybox/bow/createBowAndArrow.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
Script.include("createBow.js");
|
||||
Script.include("createArrow.js");
|
Loading…
Reference in a new issue