add ping pong gun and enable some items

This commit is contained in:
James B. Pollack 2016-03-17 01:03:21 -07:00
parent 4dd3f2a097
commit ed1913e58d
4 changed files with 279 additions and 50 deletions

View file

@ -39,7 +39,6 @@
"z": 0.046798638999462128
},
"id": "{e48fd6a5-ff0f-4ba6-92c7-fd972eba53c6}",
"locked": 1,
"modelURL": "http://hifi-content.s3.amazonaws.com/alan/dev/Book-RPO-EC.fbx",
"name": "home_model_book_readyplayerone",
"position": {

View file

@ -0,0 +1,151 @@
// pingPongGun.js
//
// Script Type: Entity
// Created by James B. Pollack @imgntn on 9/21/2015
// Copyright 2015 High Fidelity, Inc.
//
// This script shoots a ping pong ball.
// 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() {
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;
}
//if the trigger value goes below this value, reload the gun.
var RELOAD_THRESHOLD = 0.95;
var GUN_TIP_FWD_OFFSET = -0.35;
var GUN_TIP_UP_OFFSET = 0.12;
var GUN_FORCE = 9;
var BALL_RESTITUTION = 0.6;
var BALL_LINEAR_DAMPING = 0.4;
var BALL_GRAVITY = {
x: 0,
y: -4.8,
z: 0
};
var BALL_DIMENSIONS = {
x: 0.04,
y: 0.04,
z: 0.04
};
var BALL_COLOR = {
red: 255,
green: 255,
blue: 255
};
var TRIGGER_CONTROLS = [
Controller.Standard.LT,
Controller.Standard.RT,
];
PingPongGun.prototype = {
hand: null,
gunTipPosition: null,
canShoot: false,
canShootTimeout: null,
startEquip: function(entityID, args) {
this.hand = args[0] == "left" ? 0 : 1;
},
continueEquip: function(entityID, args) {
if (this.canShootTimeout !== null) {
Script.clearTimeout(this.canShootTimeout);
}
this.checkTriggerPressure(this.hand);
},
releaseEquip: function(entityID, args) {
var _this = this;
this.canShootTimeout = Script.setTimeout(function() {
_this.canShoot = false;
}, 250);
},
checkTriggerPressure: function(gunHand) {
this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[gunHand]);
if (this.triggerValue < RELOAD_THRESHOLD) {
// print('RELOAD');
this.canShoot = true;
} else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true) {
var gunProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
this.shootBall(gunProperties);
this.canShoot = false;
}
return;
},
shootBall: function(gunProperties) {
var forwardVec = Quat.getFront(Quat.multiply(gunProperties.rotation, Quat.fromPitchYawRollDegrees(0, 180, 0)));
forwardVec = Vec3.normalize(forwardVec);
forwardVec = Vec3.multiply(forwardVec, GUN_FORCE);
var properties = {
// type: 'Model',
// modelURL:PING_PONG_BALL_URL,
shapeType: 'sphere',
type: 'Sphere',
color: BALL_COLOR,
dimensions: BALL_DIMENSIONS,
damping: BALL_LINEAR_DAMPING,
gravity: BALL_GRAVITY,
restitution: BALL_RESTITUTION,
dynamic: true,
rotation: gunProperties.rotation,
position: this.getGunTipPosition(gunProperties),
velocity: forwardVec,
lifetime: 10
};
Entities.addEntity(properties);
this.playSoundAtCurrentPosition(gunProperties.position);
},
playSoundAtCurrentPosition: function(position) {
var audioProperties = {
volume: 0.2,
position: position
};
Audio.playSound(this.SHOOTING_SOUND, audioProperties);
},
getGunTipPosition: function(properties) {
//the tip of the gun is going to be in a different place than the center, so we move in space relative to the model to find that position
var frontVector = Quat.getFront(properties.rotation);
var frontOffset = Vec3.multiply(frontVector, GUN_TIP_FWD_OFFSET);
var upVector = Quat.getUp(properties.rotation);
var upOffset = Vec3.multiply(upVector, GUN_TIP_UP_OFFSET);
var gunTipPosition = Vec3.sum(properties.position, frontOffset);
gunTipPosition = Vec3.sum(gunTipPosition, upOffset);
return gunTipPosition;
},
preload: function(entityID) {
this.entityID = entityID;
this.SHOOTING_SOUND = SoundCache.getSound(SHOOTING_SOUND_URL);
}
};
// entity scripts always need to return a newly constructed object of our type
return new PingPongGun();
});

View file

@ -0,0 +1,67 @@
// createPingPongGun.js
//
// Script Type: Entity Spawner
// Created by James B. Pollack on 9/30/2015
// Copyright 2015 High Fidelity, Inc.
//
// This script creates a gun that shoots ping pong balls when you pull the trigger on a hand controller.
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.include("../utils.js");
var scriptURL = Script.resolvePath('pingPongGun.js');
var MODEL_URL = 'http://hifi-content.s3.amazonaws.com/alan/dev/Pingpong-Gun-New.fbx'
var COLLISION_HULL_URL = 'http://hifi-content.s3.amazonaws.com/alan/dev/Pingpong-Gun-New.obj';
var COLLISION_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/Collisions-otherorganic/plastic_impact.L.wav';
PingPingGun = function(spawnPosition, spawnRotation) {
var pingPongGun = Entities.addEntity({
type: "Model",
modelURL: MODEL_URL,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
script: scriptURL,
position: spawnPosition,
dimensions: {
x: 0.125,
y: 0.3875,
z: 0.9931
},
dynamic: true,
collisionSoundURL: COLLISION_SOUND_URL,
userData: JSON.stringify({
grabbableKey: {
invertSolidWhileHeld: true
},
wearable: {
joints: {
RightHand: [{
x: 0.1177130937576294,
y: 0.12922893464565277,
z: 0.08307232707738876
}, {
x: 0.4934672713279724,
y: 0.3605862259864807,
z: 0.6394805908203125,
w: -0.4664038419723511
}],
LeftHand: [{
x: 0.09151676297187805,
y: 0.13639454543590546,
z: 0.09354984760284424
}, {
x: -0.19628101587295532,
y: 0.6418180465698242,
z: 0.2830369472503662,
w: 0.6851521730422974
}]
}
}
})
});
function cleanUp() {
Entities.deleteEntity(pingPongGun);
}
}

View file

@ -31,18 +31,19 @@
var plantPath = Script.resolvePath("growingPlant/wrapper.js?" + Math.random());
var pingPingGunPath = Script.resolvePath("pingPingGun/wrapper.js?" + Math.random());
var kineticPath = Script.resolvePath("kineticObjects/wrapper.js?" + Math.random());
Script.include(kineticPath);
Reset.prototype = {
tidying: false,
preload: function(entityID) {
_this.entityID = entityID;
},
unload: function() {
this.cleanupDynamicEntities();
},
tidying: false,
showTidyingButton: function() {
var textureString =
'Texture.001:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Head-Housing-Texture.png",\ntex.face.screen.emit:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/tidy-guy-face-Emit.png",\ntex.face.sceen:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/tidy-guy-face.png",\ntex.button.blanks:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Button-Blanks.png",\ntex.button.blanks.normal:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Button-Blanks-Normal.png",\nbutton.tidy.emit:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidy-Up-Button-Orange-Emit.png",\nbutton.tidy:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidy-Up-Button-Orange.png"'
@ -51,6 +52,7 @@
textures: textureString
});
},
showTidyButton: function() {
var textureString =
'Texture.001:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Head-Housing-Texture.png",\ntex.face.screen.emit:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/tidy-guy-face-Emit.png",\ntex.face.sceen:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/tidy-guy-face.png",\ntex.button.blanks:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Button-Blanks.png",\ntex.button.blanks.normal:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Button-Blanks-Normal.png",\nbutton.tidy.emit:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Tidy-Up-Button-Green-Emit.png",\nbutton.tidy:"http://hifi-content.s3.amazonaws.com/DomainContent/Home/tidyGuy/Tidyguy-6.fbx/Tidyguy-6.fbm/Tidy-Up-Button-Green.png"'
@ -59,9 +61,11 @@
textures: textureString
});
},
playTidyingSound: function() {
},
toggleButton: function() {
if (_this.tidying === true) {
return;
@ -106,39 +110,46 @@
Script.include(whiteboardPath);
Script.include(plantPath);
// var fishTank = new FishTank({
// x: 1098.9254,
// y: 460.5814,
// z: -79.1103
// });
// var tiltMaze = new TiltMaze({
// x: 1105.5768,
// y: 460.3298,
// z: -80.4891
// });
// var whiteboard = new Whiteboard({
// x: 1104,
// y: 450,
// z: -77
// });
var fishTank = new FishTank({
x: 1098.9254,
y: 460.5814,
z: -79.1103
});
// var myPlant = new Plant(center);
var tiltMaze = new TiltMaze({
x: 1105.5768,
y: 460.3298,
z: -80.4891
});
var whiteboard = new Whiteboard({
x: 1104,
y: 450,
z: -77
});
// dynamicEntities.push(fishTank);
// dynamicEntities.push(tiltMaze);
// dynamicEntities.push(whiteboard);
//dynamicEntities.push(myPlant);
//var myPlant = new Plant(center);
var pingPongGun = new PingPongGun({
x: 1101.2123,
y: 460.2328,
z: -65.8513
});
dynamicEntities.push(pingPongGun);
dynamicEntities.push(fishTank);
dynamicEntities.push(tiltMaze);
dynamicEntities.push(whiteboard);
// dynamicEntities.push(myPlant);
//v2.0
// var musicBox = new MusicBox();
// var cuckooClock = new CuckooClock();
// var doppelganger = new Doppelganger();
//var pingPongGun = new PingPongGun({
// x:1101.2123, y:460.2328, z:-65.8513
// });
//dynamicEntities.push(pingPongGun);
},
cleanupDynamicEntities: function() {
@ -183,8 +194,8 @@
z: -80.2837
});
var rightDeskDrawer= new RightDeskDrawer({
x:1105.1735,
var rightDeskDrawer = new RightDeskDrawer({
x: 1105.1735,
y: 460.0446,
z: -81.3612
});
@ -195,21 +206,21 @@
z: -82.1095
});
// var chair = new Chair({
// x: 1105.2716,
// y: 459.7251,
// z: 79.8097
// });
// var trashcan = new Trashcan({
// x: 1104.0031,
// y: 459.4355,
// z: -82.7294
// });
// var books = new Books({
// x: 1101.2123,
// y: 460.2328,
// z: -65.8513
// });
var chair = new Chair({
x: 1105.2716,
y: 459.7251,
z: -79.8097
});
var trashcan = new Trashcan({
x: 1104.0031,
y: 459.4355,
z: -82.7294
});
var books = new Books({
x: 1101.2123,
y: 460.2328,
z: -65.8513
});
kineticEntities.push(fruitBowl);
kineticEntities.push(livingRoomLamp);
@ -217,10 +228,11 @@
kineticEntities.push(lowerBookShelf);
kineticEntities.push(rightDeskDrawer);
kineticEntities.push(leftDeskDrawer);
// kineticEntities.push(chair);
// kineticEntities.push(trashcan);
// kineticEntities.push(books);
kineticEntities.push(chair);
kineticEntities.push(trashcan);
kineticEntities.push(books);
},
cleanupKineticEntities: function() {
if (kineticEntities.length === 0) {
return;