mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
commit
e50422d5b9
2 changed files with 172 additions and 0 deletions
91
unpublishedScripts/marketplace/dart/createDart.js
Normal file
91
unpublishedScripts/marketplace/dart/createDart.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
"use strict";
|
||||
//
|
||||
// createDart.js
|
||||
//
|
||||
// Created by MrRoboman on 17/05/04
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Creates five throwing darts.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
var MODEL_URL = "https://hifi-content.s3.amazonaws.com/wadewatts/dart.fbx";
|
||||
var SCRIPT_URL = Script.resolvePath("./dart.js?v=" + Date.now());
|
||||
var START_POSITION = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 0.75));
|
||||
var START_ROTATION = MyAvatar.orientation
|
||||
var SCALE_FACTOR = 1;
|
||||
|
||||
var dart = {
|
||||
type: "Model",
|
||||
shapeType: "box",
|
||||
name: "Dart",
|
||||
description: "Throw it at something!",
|
||||
script: SCRIPT_URL,
|
||||
modelURL: MODEL_URL,
|
||||
position: START_POSITION,
|
||||
rotation: START_ROTATION,
|
||||
lifetime: 300,
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -9.8,
|
||||
z: 0
|
||||
},
|
||||
dimensions: {
|
||||
x: 0.1,
|
||||
y: 0.1,
|
||||
z: 0.3
|
||||
},
|
||||
dynamic: true,
|
||||
owningAvatarID: MyAvatar.sessionUUID,
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
grabbable: true,
|
||||
invertSolidWhileHeld: true,
|
||||
ignoreIK: false
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
var avatarUp = Quat.getUp(MyAvatar.orientation);
|
||||
var platformPosition = Vec3.sum(START_POSITION, Vec3.multiply(avatarUp, -0.05));
|
||||
var platform = {
|
||||
type: "Box",
|
||||
name: "Dart Platform",
|
||||
description: "Holds darts",
|
||||
position: platformPosition,
|
||||
rotation: START_ROTATION,
|
||||
lifetime: 60,
|
||||
dimensions: {
|
||||
x: 0.15 * 5,
|
||||
y: 0.01,
|
||||
z: 0.3
|
||||
},
|
||||
color: {
|
||||
red: 129,
|
||||
green: 92,
|
||||
blue: 11
|
||||
},
|
||||
owningAvatarID: MyAvatar.sessionUUID,
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
grabbable: true,
|
||||
invertSolidWhileHeld: true,
|
||||
ignoreIK: false
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
Entities.addEntity(platform);
|
||||
|
||||
var dartCount = 5;
|
||||
var avatarRight = Quat.getRight(MyAvatar.orientation);
|
||||
for (var i = 0; i < dartCount; i++) {
|
||||
var j = i - Math.floor(dartCount / 2);
|
||||
var position = Vec3.sum(START_POSITION, Vec3.multiply(avatarRight, 0.15 * j));
|
||||
dart.position = position;
|
||||
Entities.addEntity(dart);
|
||||
}
|
||||
|
||||
Script.stop();
|
81
unpublishedScripts/marketplace/dart/dart.js
Normal file
81
unpublishedScripts/marketplace/dart/dart.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
"use strict";
|
||||
//
|
||||
// dart.js
|
||||
//
|
||||
// Created by MrRoboman on 17/05/13
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Simple throwing dart. Sticks to static objects.
|
||||
//
|
||||
// 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 THROW_FACTOR = 3;
|
||||
var DART_SOUND_URL = Script.resolvePath('https://hifi-content.s3.amazonaws.com/wadewatts/dart.wav?v=' + Date.now());
|
||||
|
||||
var Dart = function() {};
|
||||
|
||||
Dart.prototype = {
|
||||
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
this.actionID = null;
|
||||
this.soundHasPlayed = true;
|
||||
this.dartSound = SoundCache.getSound(DART_SOUND_URL);
|
||||
},
|
||||
|
||||
playDartSound: function(sound) {
|
||||
if (this.soundHasPlayed) {
|
||||
return;
|
||||
}
|
||||
this.soundHasPlayed = true;
|
||||
var position = Entities.getEntityProperties(this.entityID, 'position').position;
|
||||
var audioProperties = {
|
||||
volume: 0.15,
|
||||
position: position
|
||||
};
|
||||
Audio.playSound(this.dartSound, audioProperties);
|
||||
},
|
||||
|
||||
releaseGrab: function() {
|
||||
this.soundHasPlayed = false;
|
||||
var velocity = Entities.getEntityProperties(this.entityID, 'velocity').velocity;
|
||||
|
||||
var newVelocity = {};
|
||||
Object.keys(velocity).forEach(function(key) {
|
||||
newVelocity[key] = velocity[key] * THROW_FACTOR;
|
||||
});
|
||||
|
||||
Entities.editEntity(this.entityID, {
|
||||
velocity: newVelocity
|
||||
});
|
||||
|
||||
if (this.actionID) {
|
||||
Entities.deleteAction(this.entityID, this.actionID);
|
||||
}
|
||||
this.actionID = Entities.addAction("travel-oriented", this.entityID, {
|
||||
forward: { x: 0, y: 0, z: 1 },
|
||||
angularTimeScale: 0.1,
|
||||
tag: "throwing dart",
|
||||
ttl: 3600
|
||||
});
|
||||
},
|
||||
|
||||
collisionWithEntity: function(myID, otherID, collisionInfo) {
|
||||
this.playDartSound();
|
||||
|
||||
Entities.editEntity(myID, {
|
||||
velocity: {x: 0, y: 0, z: 0},
|
||||
angularVelocity: {x: 0, y: 0, z: 0}
|
||||
});
|
||||
|
||||
if (this.actionID) {
|
||||
Entities.deleteAction(myID, this.actionID);
|
||||
this.actionID = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return new Dart();
|
||||
});
|
Loading…
Reference in a new issue