mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-19 13:33:15 +02:00
bow, arrow, createbow
This commit is contained in:
parent
62206b747f
commit
3ddfce911e
3 changed files with 134 additions and 12 deletions
48
examples/toys/bow/arrow.js
Normal file
48
examples/toys/bow/arrow.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// 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() {
|
||||
|
||||
var _this;
|
||||
|
||||
function Arrow() {
|
||||
_this = this;
|
||||
return;
|
||||
}
|
||||
|
||||
Arrow.prototype = {
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
},
|
||||
collisionWithEntity: function(me, otherEntity, collision) {
|
||||
|
||||
Vec3.print('penetration = ', collision.penetration);
|
||||
Vec3.print('collision contact point = ', collision.contactPoint);
|
||||
|
||||
Entities.editEntity(this.entityID, {
|
||||
velocity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
collisionsWillMove: false
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
return new Arrow;
|
||||
})
|
|
@ -1,8 +1,9 @@
|
|||
//
|
||||
// bow.js
|
||||
//
|
||||
// This script creates a bow that you can pick up with a hand controller. Use your other hand and press the trigger to grab the line, and release the trigger to fire.
|
||||
// Created by James B. Pollack @imgntn on 10/10/2015
|
||||
// This script attaches to a bow that you can pick up with a hand controller. Use your other hand and press the trigger to grab the line, and release the trigger to fire.
|
||||
//
|
||||
// Created by James B. Pollack @imgntn on 10/19/2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
|
@ -10,7 +11,20 @@
|
|||
//
|
||||
|
||||
(function() {
|
||||
|
||||
var ARROW_MODEL_URL = '';
|
||||
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js');
|
||||
var ARROW_OFFSET = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
var ARROW_GRAVITY = {
|
||||
x: 0,
|
||||
y: -9.8,
|
||||
z: 0
|
||||
};
|
||||
|
||||
var TOP_NOTCH_OFFSET = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
@ -24,6 +38,7 @@
|
|||
};
|
||||
|
||||
var DRAW_STRING_THRESHOLD = 0.1;
|
||||
var RELEASE_STRING_THRESHOLD = 0.85;
|
||||
|
||||
var _this;
|
||||
|
||||
|
@ -67,6 +82,8 @@
|
|||
strokeWidths: this.stringData.bottom.strokeWidths,
|
||||
color: stringData.currentColor
|
||||
});
|
||||
|
||||
this.stringDrawn = true;
|
||||
},
|
||||
|
||||
createStrings: function() {
|
||||
|
@ -80,7 +97,6 @@
|
|||
},
|
||||
|
||||
createTopString: function() {
|
||||
|
||||
var stringProperties = {
|
||||
type: 'Polyline'
|
||||
position: Vec3.sum(this.position, this.TOP_NOTCH_OFFSET);
|
||||
|
@ -90,7 +106,6 @@
|
|||
},
|
||||
|
||||
createBottomString: function() {
|
||||
|
||||
var stringProperties = {
|
||||
type: 'Polyline'
|
||||
position: Vec3.sum(this.position, this.TOP_NOTCH_OFFSET);
|
||||
|
@ -129,30 +144,44 @@
|
|||
|
||||
this.triggerValue = Controller.getActionValue(handClick);
|
||||
|
||||
if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
||||
if (this.triggerValue < RELEASE_STRING_THRESHOLD && this.stringDrawn === true) {
|
||||
|
||||
this.releaseArrow();
|
||||
this.stringDrawn = false;
|
||||
|
||||
this.deleteStrings();
|
||||
|
||||
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === false) {
|
||||
|
||||
this.stringData.handPosition = this.getStringHandPosition();
|
||||
this.stringData.handRotation = this.getStringHandRotation();
|
||||
this.drawStrings();
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
|
||||
releaseArrow: function() {
|
||||
|
||||
var handDistanceAtRelease = Vec3.length(this.bowProperties.position, this.stringData.handPosition);
|
||||
var releaseDirection = this.stringData.handRotation;
|
||||
var releaseVecotr = 'something';
|
||||
var releaseDirection = Vec3.subtract(this.bowProperties.position, this.stringData.handPosition);
|
||||
var releaseVector = Vec3.multiply(handDistanceAtRelease, releaseDirection);
|
||||
|
||||
var arrowProperties = {
|
||||
type: 'Model',
|
||||
dimensions: ARROW_DIMENSIONS,
|
||||
position: Vec3.sum(this.bowProperties.position, ARROW_OFFSET),
|
||||
velocity: relesaeVector,
|
||||
velocity: releaseVector,
|
||||
rotation: this.bowProperties.rotation;
|
||||
collisionsWillMove: true,
|
||||
gravity: ARROW_GRAVITY,
|
||||
script: ARROW_SCRIPT_URL,
|
||||
lifetime: 30
|
||||
};
|
||||
this.arrow = Entities.addEntity(arrowProperties);
|
||||
}
|
||||
|
||||
return new Bow;
|
||||
this.arrow = Entities.addEntity(arrowProperties);
|
||||
},
|
||||
|
||||
|
||||
return new Bow;
|
||||
})
|
45
examples/toys/bow/createBow.js
Normal file
45
examples/toys/bow/createBow.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// createBow.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 SCRIPT_URL = Script.resolvePath('bow.js');
|
||||
|
||||
var MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/bow.fbx";
|
||||
var COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/bow_collision_hull.obj";
|
||||
var BOW_DIMENSIONS = {
|
||||
x: 0.08,
|
||||
y: 0.30,
|
||||
z: 0.08
|
||||
};
|
||||
|
||||
var BOW_GRAVITY = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
|
||||
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
|
||||
x: 0,
|
||||
y: 0.5,
|
||||
z: 0
|
||||
}), Vec3.multiply(1, Quat.getFront(Camera.getOrientation())));
|
||||
|
||||
var flashlight = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: MODEL_URL,
|
||||
position: center,
|
||||
dimensions: BOW_DIMENSIONS,
|
||||
collisionsWillMove: true,
|
||||
gravity: BOW_GRAVITY,
|
||||
shapeType: 'compound',
|
||||
script: SCRIPT_URL
|
||||
});
|
Loading…
Reference in a new issue