mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Merge pull request #6032 from imgntn/wall_targets
[Scripts] Add Wall Targets to Toybox
This commit is contained in:
commit
9d949da19c
5 changed files with 360 additions and 8 deletions
|
@ -13,8 +13,8 @@ Script.include("../../utilities.js");
|
|||
|
||||
var scriptURL = Script.resolvePath('pingPongGun.js');
|
||||
|
||||
var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun.fbx?123'
|
||||
var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun_collision_hull.obj?123';
|
||||
var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun.fbx'
|
||||
var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun_collision_hull.obj';
|
||||
|
||||
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
|
||||
x: 0,
|
||||
|
|
154
examples/toys/ping_pong_gun/createTargets.js
Normal file
154
examples/toys/ping_pong_gun/createTargets.js
Normal file
|
@ -0,0 +1,154 @@
|
|||
// createTargets.js
|
||||
//
|
||||
// Script Type: Entity Spawner
|
||||
// Created by James B. Pollack on 9/30/2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// This script creates targets that fall down when you shoot them and then automatically reset to their original position.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
/*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */
|
||||
Script.include("../../utilities.js");
|
||||
Script.include("../../libraries/utils.js");
|
||||
var scriptURL = Script.resolvePath('wallTarget.js');
|
||||
|
||||
var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target.fbx';
|
||||
var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target_collision_hull.obj';
|
||||
|
||||
var RESET_DISTANCE = 1;
|
||||
var TARGET_USER_DATA_KEY = 'hifi-ping_pong_target';
|
||||
var NUMBER_OF_TARGETS = 6;
|
||||
var TARGETS_PER_ROW = 3;
|
||||
|
||||
var TARGET_DIMENSIONS = {
|
||||
x: 0.06,
|
||||
y: 0.42,
|
||||
z: 0.42
|
||||
};
|
||||
|
||||
var VERTICAL_SPACING = TARGET_DIMENSIONS.y + 0.5;
|
||||
var HORIZONTAL_SPACING = TARGET_DIMENSIONS.z + 0.5;
|
||||
|
||||
|
||||
var startPosition = {
|
||||
x: 548.68,
|
||||
y: 497.30,
|
||||
z: 509.74
|
||||
};
|
||||
|
||||
var rotation = Quat.fromPitchYawRollDegrees(0, -55.25, 0);
|
||||
|
||||
var targetIntervalClearer = Entities.addEntity({
|
||||
name: 'Target Interval Clearer - delete me to clear',
|
||||
type: 'Box',
|
||||
position: startPosition,
|
||||
dimensions: TARGET_DIMENSIONS,
|
||||
color: {
|
||||
red: 0,
|
||||
green: 255,
|
||||
blue: 0
|
||||
},
|
||||
rotation: rotation,
|
||||
visible: false,
|
||||
collisionsWillMove: false,
|
||||
ignoreForCollisions: true,
|
||||
});
|
||||
|
||||
var targets = [];
|
||||
|
||||
var originalPositions = [];
|
||||
|
||||
function addTargets() {
|
||||
var i;
|
||||
var row = -1;
|
||||
|
||||
for (i = 0; i < NUMBER_OF_TARGETS; i++) {
|
||||
|
||||
if (i % TARGETS_PER_ROW === 0) {
|
||||
row++;
|
||||
}
|
||||
|
||||
var vHat = Quat.getFront(rotation);
|
||||
var spacer = HORIZONTAL_SPACING * (i % TARGETS_PER_ROW) + (row * HORIZONTAL_SPACING / 2);
|
||||
var multiplier = Vec3.multiply(spacer, vHat);
|
||||
var position = Vec3.sum(startPosition, multiplier);
|
||||
position.y = startPosition.y - (row * VERTICAL_SPACING);
|
||||
|
||||
originalPositions.push(position);
|
||||
|
||||
var targetProperties = {
|
||||
name: 'Target',
|
||||
type: 'Model',
|
||||
modelURL: MODEL_URL,
|
||||
shapeType: 'compound',
|
||||
collisionsWillMove: true,
|
||||
dimensions: TARGET_DIMENSIONS,
|
||||
compoundShapeURL: COLLISION_HULL_URL,
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
script: scriptURL
|
||||
};
|
||||
|
||||
targets.push(Entities.addEntity(targetProperties));
|
||||
}
|
||||
}
|
||||
|
||||
function testTargetDistanceFromStart() {
|
||||
targets.forEach(function(target, index) {
|
||||
|
||||
var currentPosition = Entities.getEntityProperties(target, "position").position;
|
||||
var originalPosition = originalPositions[index];
|
||||
var distance = Vec3.subtract(originalPosition, currentPosition);
|
||||
var length = Vec3.length(distance);
|
||||
|
||||
if (length > RESET_DISTANCE) {
|
||||
|
||||
Entities.deleteEntity(target);
|
||||
|
||||
var targetProperties = {
|
||||
name: 'Target',
|
||||
type: 'Model',
|
||||
modelURL: MODEL_URL,
|
||||
shapeType: 'compound',
|
||||
collisionsWillMove: true,
|
||||
dimensions: TARGET_DIMENSIONS,
|
||||
compoundShapeURL: COLLISION_HULL_URL,
|
||||
position: originalPositions[index],
|
||||
rotation: rotation,
|
||||
script: scriptURL
|
||||
};
|
||||
|
||||
targets[index] = Entities.addEntity(targetProperties);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function deleteEntity(entityID) {
|
||||
if (entityID === targetIntervalClearer) {
|
||||
deleteTargets();
|
||||
Script.clearInterval(distanceCheckInterval);
|
||||
Entities.deletingEntity.disconnect(deleteEntity);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteTargets() {
|
||||
while (targets.length > 0) {
|
||||
Entities.deleteEntity(targets.pop());
|
||||
}
|
||||
Entities.deleteEntity(targetIntervalClearer);
|
||||
}
|
||||
|
||||
Entities.deletingEntity.connect(deleteEntity);
|
||||
var distanceCheckInterval = Script.setInterval(testTargetDistanceFromStart, 1000);
|
||||
|
||||
addTargets();
|
||||
|
||||
function atEnd() {
|
||||
Script.clearInterval(distanceCheckInterval);
|
||||
deleteTargets();
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(atEnd);
|
|
@ -14,6 +14,7 @@
|
|||
Script.include("../../libraries/utils.js");
|
||||
|
||||
var SHOOTING_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/ping_pong_gun/pong_sound.wav';
|
||||
var PING_PONG_BALL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_ball.fbx';
|
||||
|
||||
function PingPongGun() {
|
||||
return;
|
||||
|
@ -23,7 +24,7 @@
|
|||
var RELOAD_THRESHOLD = 0.95;
|
||||
var GUN_TIP_FWD_OFFSET =-0.35;
|
||||
var GUN_TIP_UP_OFFSET = 0.040;
|
||||
var GUN_FORCE = 9;
|
||||
var GUN_FORCE = 5;
|
||||
var BALL_RESTITUTION = 0.6;
|
||||
var BALL_LINEAR_DAMPING = 0.4;
|
||||
var BALL_GRAVITY = {
|
||||
|
@ -115,7 +116,10 @@
|
|||
forwardVec = Vec3.multiply(forwardVec, GUN_FORCE);
|
||||
|
||||
var properties = {
|
||||
type: 'Sphere',
|
||||
// type: 'Model',
|
||||
// modelURL:PING_PONG_BALL_URL,
|
||||
shapeType:'sphere',
|
||||
type:'Sphere',
|
||||
color: BALL_COLOR,
|
||||
dimensions: BALL_DIMENSIONS,
|
||||
linearDamping: BALL_LINEAR_DAMPING,
|
||||
|
|
56
examples/toys/ping_pong_gun/wallTarget.js
Normal file
56
examples/toys/ping_pong_gun/wallTarget.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// wallTarget.js
|
||||
//
|
||||
// Script Type: Entity
|
||||
// Created by James B. Pollack @imgntn on 9/21/2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// This script resets an object to its original position when it stops moving after a collision
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */
|
||||
(function() {
|
||||
|
||||
|
||||
function Target() {
|
||||
return;
|
||||
}
|
||||
|
||||
Target.prototype = {
|
||||
hasPlayedSound: false,
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
var SOUND_URL = "http://hifi-public.s3.amazonaws.com/sounds/Clay_Pigeon_02.L.wav";
|
||||
this.hitSound = SoundCache.getSound(SOUND_URL);
|
||||
},
|
||||
collisionWithEntity: function(me, otherEntity) {
|
||||
var position = Entities.getEntityProperties(me, "position").position;
|
||||
Entities.editEntity(me, {
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -9.8,
|
||||
z: 0
|
||||
},
|
||||
velocity: {
|
||||
x: 0,
|
||||
y: -0.01,
|
||||
z: 0
|
||||
}
|
||||
});
|
||||
|
||||
if (this.hasPlayedSound === false) {
|
||||
this.audioInjector = Audio.playSound(this.hitSound, {
|
||||
position: position,
|
||||
volume: 0.5
|
||||
});
|
||||
|
||||
this.hasPlayedSound = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// entity scripts always need to return a newly constructed object of our type
|
||||
return new Target();
|
||||
});
|
|
@ -21,10 +21,11 @@ var pingPongScriptURL = Script.resolvePath('../examples/toys/ping_pong_gun/pingP
|
|||
var wandScriptURL = Script.resolvePath("../examples/toys/bubblewand/wand.js");
|
||||
var dollScriptURL = Script.resolvePath("../examples/toys/doll/doll.js");
|
||||
var lightsScriptURL = Script.resolvePath("../examples/toys/lightSwitch.js");
|
||||
var targetsScriptURL = Script.resolvePath('../examples/toys/ping_pong_gun/wallTarget.js');
|
||||
|
||||
|
||||
|
||||
MasterReset = function () {
|
||||
MasterReset = function() {
|
||||
var resetKey = "resetMe";
|
||||
var GRABBABLE_DATA_KEY = "grabbableKey";
|
||||
|
||||
|
@ -109,12 +110,14 @@ MasterReset = function () {
|
|||
z: 503.91
|
||||
});
|
||||
|
||||
createTargets();
|
||||
|
||||
}
|
||||
|
||||
function deleteAllToys() {
|
||||
var entities = Entities.findEntities(MyAvatar.position, 100);
|
||||
|
||||
entities.forEach(function (entity) {
|
||||
entities.forEach(function(entity) {
|
||||
//params: customKey, id, defaultValue
|
||||
var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe;
|
||||
if (shouldReset === true) {
|
||||
|
@ -299,14 +302,14 @@ MasterReset = function () {
|
|||
function testBallDistanceFromStart() {
|
||||
var resetCount = 0;
|
||||
|
||||
collidingBalls.forEach(function (ball, index) {
|
||||
collidingBalls.forEach(function(ball, index) {
|
||||
var currentPosition = Entities.getEntityProperties(ball, "position").position;
|
||||
var originalPosition = originalBallPositions[index];
|
||||
var distance = Vec3.subtract(originalPosition, currentPosition);
|
||||
var length = Vec3.length(distance);
|
||||
|
||||
if (length > RESET_DISTANCE) {
|
||||
Script.setTimeout(function () {
|
||||
Script.setTimeout(function() {
|
||||
var newPosition = Entities.getEntityProperties(ball, "position").position;
|
||||
var moving = Vec3.length(Vec3.subtract(currentPosition, newPosition));
|
||||
if (moving < MINIMUM_MOVE_LENGTH) {
|
||||
|
@ -341,6 +344,141 @@ MasterReset = function () {
|
|||
var distanceCheckInterval = Script.setInterval(testBallDistanceFromStart, 1000);
|
||||
}
|
||||
|
||||
function createTargets() {
|
||||
|
||||
var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target.fbx';
|
||||
var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target_collision_hull.obj';
|
||||
|
||||
var RESET_DISTANCE = 1;
|
||||
var TARGET_USER_DATA_KEY = 'hifi-ping_pong_target';
|
||||
var NUMBER_OF_TARGETS = 6;
|
||||
var TARGETS_PER_ROW = 3;
|
||||
|
||||
var TARGET_DIMENSIONS = {
|
||||
x: 0.06,
|
||||
y: 0.42,
|
||||
z: 0.42
|
||||
};
|
||||
|
||||
var VERTICAL_SPACING = TARGET_DIMENSIONS.y + 0.5;
|
||||
var HORIZONTAL_SPACING = TARGET_DIMENSIONS.z + 0.5;
|
||||
|
||||
|
||||
var startPosition = {
|
||||
x: 548.68,
|
||||
y: 497.30,
|
||||
z: 509.74
|
||||
};
|
||||
|
||||
var rotation = Quat.fromPitchYawRollDegrees(0, -55.25, 0);
|
||||
|
||||
var targetIntervalClearer = Entities.addEntity({
|
||||
name: 'Target Interval Clearer - delete me to clear',
|
||||
type: 'Box',
|
||||
position: startPosition,
|
||||
dimensions: TARGET_DIMENSIONS,
|
||||
color: {
|
||||
red: 0,
|
||||
green: 255,
|
||||
blue: 0
|
||||
},
|
||||
rotation: rotation,
|
||||
visible: false,
|
||||
collisionsWillMove: false,
|
||||
ignoreForCollisions: true,
|
||||
});
|
||||
|
||||
var targets = [];
|
||||
|
||||
var originalPositions = [];
|
||||
|
||||
function addTargets() {
|
||||
var i;
|
||||
var row = -1;
|
||||
for (i = 0; i < NUMBER_OF_TARGETS; i++) {
|
||||
|
||||
if (i % TARGETS_PER_ROW === 0) {
|
||||
row++;
|
||||
}
|
||||
|
||||
var vHat = Quat.getFront(rotation);
|
||||
var spacer = HORIZONTAL_SPACING * (i % TARGETS_PER_ROW) + (row * HORIZONTAL_SPACING / 2);
|
||||
var multiplier = Vec3.multiply(spacer, vHat);
|
||||
var position = Vec3.sum(startPosition, multiplier);
|
||||
position.y = startPosition.y - (row * VERTICAL_SPACING);
|
||||
|
||||
originalPositions.push(position);
|
||||
|
||||
var targetProperties = {
|
||||
name: 'Target',
|
||||
type: 'Model',
|
||||
modelURL: MODEL_URL,
|
||||
shapeType: 'compound',
|
||||
collisionsWillMove: true,
|
||||
dimensions: TARGET_DIMENSIONS,
|
||||
compoundShapeURL: COLLISION_HULL_URL,
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
script: targetsScriptURL
|
||||
};
|
||||
|
||||
targets.push(Entities.addEntity(targetProperties));
|
||||
}
|
||||
}
|
||||
|
||||
function testTargetDistanceFromStart() {
|
||||
targets.forEach(function(target, index) {
|
||||
|
||||
var currentPosition = Entities.getEntityProperties(target, "position").position;
|
||||
var originalPosition = originalPositions[index];
|
||||
var distance = Vec3.subtract(originalPosition, currentPosition);
|
||||
var length = Vec3.length(distance);
|
||||
|
||||
if (length > RESET_DISTANCE) {
|
||||
|
||||
Entities.deleteEntity(target);
|
||||
|
||||
var targetProperties = {
|
||||
name: 'Target',
|
||||
type: 'Model',
|
||||
modelURL: MODEL_URL,
|
||||
shapeType: 'compound',
|
||||
collisionsWillMove: true,
|
||||
dimensions: TARGET_DIMENSIONS,
|
||||
compoundShapeURL: COLLISION_HULL_URL,
|
||||
position: originalPositions[index],
|
||||
rotation: rotation,
|
||||
script: targetsScriptURL
|
||||
};
|
||||
|
||||
targets[index] = Entities.addEntity(targetProperties);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function deleteEntity(entityID) {
|
||||
if (entityID === targetIntervalClearer) {
|
||||
deleteTargets();
|
||||
Script.clearInterval(distanceCheckInterval);
|
||||
Entities.deletingEntity.disconnect(deleteEntity);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteTargets() {
|
||||
while (targets.length > 0) {
|
||||
Entities.deleteEntity(targets.pop());
|
||||
}
|
||||
Entities.deleteEntity(targetIntervalClearer);
|
||||
}
|
||||
|
||||
Entities.deletingEntity.connect(deleteEntity);
|
||||
var distanceCheckInterval = Script.setInterval(testTargetDistanceFromStart, 1000);
|
||||
|
||||
addTargets();
|
||||
|
||||
}
|
||||
|
||||
function createCat(position) {
|
||||
|
||||
var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx";
|
||||
|
|
Loading…
Reference in a new issue