Merge pull request #5979 from imgntn/ping_pong_gun

[Script] Updates to Ping Pong Gun
This commit is contained in:
Eric Levin 2015-10-06 09:47:53 -07:00
commit 0afaf84e2a
3 changed files with 35 additions and 30 deletions

View file

@ -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'
var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun_collision_hull.obj';
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 center = Vec3.sum(Vec3.sum(MyAvatar.position, {
x: 0,
@ -25,14 +25,15 @@ var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
var pingPongGun = Entities.addEntity({
type: "Model",
modelURL: MODEL_URL,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
shapeType:'box',
// shapeType: 'compound',
// compoundShapeURL: COLLISION_HULL_URL,
script: scriptURL,
position: center,
dimensions: {
x:0.67,
y: 0.14,
z: 0.09
x: 0.08,
y: 0.21,
z: 0.47
},
collisionsWillMove: true,
});
@ -40,4 +41,4 @@ var pingPongGun = Entities.addEntity({
function cleanUp() {
Entities.deleteEntity(pingPongGun);
}
Script.scriptEnding.connect(cleanUp);
Script.scriptEnding.connect(cleanUp);

View file

@ -21,14 +21,14 @@
//if the trigger value goes below this value, reload the gun.
var RELOAD_THRESHOLD = 0.95;
var GUN_TIP_FWD_OFFSET = 0.45;
var GUN_TIP_FWD_OFFSET =-0.35;
var GUN_TIP_UP_OFFSET = 0.040;
var GUN_FORCE = 15;
var GUN_FORCE = 9;
var BALL_RESTITUTION = 0.6;
var BALL_LINEAR_DAMPING = 0.4;
var BALL_GRAVITY = {
x: 0,
y: -9.8,
y: -4.8,
z: 0
};
@ -36,14 +36,14 @@
x: 0.04,
y: 0.04,
z: 0.04
}
};
var BALL_COLOR = {
red: 255,
green: 255,
blue: 255
}
};
PingPongGun.prototype = {
hand: null,
@ -68,7 +68,6 @@
},
continueNearGrab: function() {
if (this.whichHand === null) {
//only set the active hand once -- if we always read the current hand, our 'holding' hand will get overwritten
this.setWhichHand();
@ -81,10 +80,14 @@
},
releaseGrab: function() {
var _t = this;
this.canShootTimeout = Script.setTimeout(function() {
_t.canShoot = false;
}, 250)
var _this = this;
if (this.whichHand === this.hand) {
this.whichHand = null;
this.canShootTimeout = Script.setTimeout(function() {
_this.canShoot = false;
}, 250);
}
},
checkTriggerPressure: function(gunHand) {
@ -97,18 +100,20 @@
if (this.triggerValue < RELOAD_THRESHOLD) {
// print('RELOAD');
this.canShoot = true;
} else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true) {
} else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true && this.hand === this.whichHand) {
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, -90, 0)));
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: 'Sphere',
color: BALL_COLOR,
@ -130,7 +135,7 @@
playSoundAtCurrentPosition: function(position) {
var audioProperties = {
volume: 0.1,
volume: 0.2,
position: position
};
@ -139,12 +144,14 @@
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.getRight(properties.rotation);
var frontVector = Quat.getFront(properties.rotation);
var frontOffset = Vec3.multiply(frontVector, GUN_TIP_FWD_OFFSET);
var upVector = Quat.getRight(properties.rotation);
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;
},

View file

@ -457,8 +457,7 @@ function createPingPongBallGun() {
var pingPongGun = Entities.addEntity({
type: "Model",
modelURL: MODEL_URL,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
shapeType: 'box',
script: scriptURL,
position: position,
rotation: rotation,
@ -468,9 +467,9 @@ function createPingPongBallGun() {
z: 0
},
dimensions: {
x: 0.67,
y: 0.14,
z: 0.09
x: 0.08,
y: 0.21,
z: 0.47
},
collisionsWillMove: true,
});
@ -478,8 +477,6 @@ function createPingPongBallGun() {
setEntityCustomData(resetKey, pingPongGun, {
resetMe: true
});
}
function createBasketballHoop() {