finish rack and add to master script, reorganize all bball related scripts

This commit is contained in:
James B. Pollack 2015-10-06 11:28:36 -07:00
parent 152fdb8112
commit 5f2112b8a5
4 changed files with 104 additions and 7 deletions

View file

@ -5,7 +5,6 @@
// Copyright 2015 High Fidelity, Inc.
//
// This is a script that creates a persistent basketball hoop with a working collision hull. Feel free to move it.
// Run basketball.js to make a basketball.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html

View file

@ -17,7 +17,6 @@ var basketballURL = HIFI_PUBLIC_BUCKET + "models/content/basketball2.fbx";
var collisionSoundURL = HIFI_PUBLIC_BUCKET + "sounds/basketball/basketball.wav";
var rackURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/basketball_rack.fbx";
var rackCollisionHullURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/rack_collision_hull.obj";
var basketballSwitcherURL = Script.resolvePath('basketballSwitcher.js');
var NUMBER_OF_BALLS = 4;
var DIAMETER = 0.30;
@ -33,7 +32,7 @@ var rackStartPosition =
}));
var rack = Entities.addEntity({
name:'Basketball Rack',
name: 'Basketball Rack',
type: "Model",
modelURL: rackURL,
position: rackStartPosition,
@ -43,7 +42,7 @@ var rack = Entities.addEntity({
y: -9.8,
z: 0
},
linearDamping:1,
linearDamping: 1,
dimensions: {
x: 0.4,
y: 1.37,
@ -51,6 +50,7 @@ var rack = Entities.addEntity({
},
collisionsWillMove: true,
ignoreForCollisions: false,
collisionSoundURL: collisionSoundURL,
compoundShapeURL: rackCollisionHullURL
});

View file

@ -1,5 +1,5 @@
//
// basketball.js
// createSingleBasketball.js
// examples
//
// Created by Philip Rosedale on August 20, 2015

View file

@ -85,6 +85,8 @@ function createAllToys() {
createBasketballHoop();
createBasketallRack();
createGates();
createFire();
@ -98,7 +100,7 @@ function createAllToys() {
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) {
@ -521,6 +523,102 @@ function createBasketballHoop() {
});
}
function createBasketallRack() {
var NUMBER_OF_BALLS = 4;
var DIAMETER = 0.30;
var basketballURL = HIFI_PUBLIC_BUCKET + "models/content/basketball2.fbx";
var basketballCollisionSoundURL = HIFI_PUBLIC_BUCKET + "sounds/basketball/basketball.wav";
var rackURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/basketball_rack.fbx";
var rackCollisionHullURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/rack_collision_hull.obj";
var rackRotation = Quat.fromPitchYawRollDegrees(0, -90, 0);
var rackStartPosition = {
x: 542.86,
y: 494.84,
z: 475.06
};
var rack = Entities.addEntity({
name: 'Basketball Rack',
type: "Model",
modelURL: rackURL,
position: rackStartPosition,
rotation: rackRotation,
shapeType: 'compound',
gravity: {
x: 0,
y: -9.8,
z: 0
},
linearDamping: 1,
dimensions: {
x: 0.4,
y: 1.37,
z: 1.73
},
collisionsWillMove: true,
ignoreForCollisions: false,
compoundShapeURL: rackCollisionHullURL
});
setEntityCustomData(resetKey, rack, {
resetMe: true
});
setEntityCustomData(GRABBABLE_DATA_KEY, rack, {
grabbable: false
});
var collidingBalls = [];
function createCollidingBalls() {
var position = rackStartPosition;
var i;
for (i = 0; i < NUMBER_OF_BALLS; i++) {
var collidingBall = Entities.addEntity({
type: "Model",
name: 'Colliding Basketball',
shapeType: 'Sphere',
position: {
x: position.x + (DIAMETER*2) - (DIAMETER * i),
y: position.y + DIAMETER * 2,
z: position.z
},
dimensions: {
x: DIAMETER,
y: DIAMETER,
z: DIAMETER
},
restitution: 1.0,
linearDamping: 0.00001,
gravity: {
x: 0,
y: -9.8,
z: 0
},
collisionsWillMove: true,
ignoreForCollisions: false,
collisionSoundURL: basketballCollisionSoundURL,
modelURL: basketballURL,
});
collidingBalls.push(collidingBall);
setEntityCustomData(resetKey, collidingBall, {
resetMe: true
});
}
}
createCollidingBalls();
}
function createWand(position) {
var WAND_MODEL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx';
var WAND_COLLISION_SHAPE = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/actual_no_top_collision_hull.obj';
@ -831,4 +929,4 @@ function cleanup() {
if (shouldDeleteOnEndScript) {
Script.scriptEnding.connect(cleanup);
}
}