ping pong gun

This commit is contained in:
James Pollack 2015-10-02 15:56:26 -07:00
parent c6fa132dc2
commit 9427ba1a5a
2 changed files with 13 additions and 10 deletions

View file

@ -13,8 +13,8 @@ Script.include("../../utilities.js");
var scriptURL = Script.resolvePath('pingPongGun.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 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'; 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, { var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
x: 0, x: 0,
@ -30,9 +30,9 @@ var pingPongGun = Entities.addEntity({
script: scriptURL, script: scriptURL,
position: center, position: center,
dimensions: { dimensions: {
x:0.67, x: 0.08,
y: 0.14, y: 0.21,
z: 0.09 z: 0.47
}, },
collisionsWillMove: true, collisionsWillMove: true,
}); });
@ -40,4 +40,4 @@ var pingPongGun = Entities.addEntity({
function cleanUp() { function cleanUp() {
Entities.deleteEntity(pingPongGun); Entities.deleteEntity(pingPongGun);
} }
Script.scriptEnding.connect(cleanUp); Script.scriptEnding.connect(cleanUp);

View file

@ -81,15 +81,14 @@
}, },
releaseGrab: function() { releaseGrab: function() {
var _t = this; var _this = this;
if (this.whichHand === this.hand) { if (this.whichHand === this.hand) {
_t.whichHand = null; this.whichHand = null;
this.canShootTimeout = Script.setTimeout(function() { this.canShootTimeout = Script.setTimeout(function() {
_t.canShoot = false; _this.canShoot = false;
}, 250); }, 250);
} }
}, },
checkTriggerPressure: function(gunHand) { checkTriggerPressure: function(gunHand) {
@ -107,6 +106,7 @@
this.shootBall(gunProperties); this.shootBall(gunProperties);
this.canShoot = false; this.canShoot = false;
} }
return; return;
}, },
@ -114,6 +114,7 @@
var forwardVec = Quat.getFront(Quat.multiply(gunProperties.rotation, Quat.fromPitchYawRollDegrees(0, -90, 0))); var forwardVec = Quat.getFront(Quat.multiply(gunProperties.rotation, Quat.fromPitchYawRollDegrees(0, -90, 0)));
forwardVec = Vec3.normalize(forwardVec); forwardVec = Vec3.normalize(forwardVec);
forwardVec = Vec3.multiply(forwardVec, GUN_FORCE); forwardVec = Vec3.multiply(forwardVec, GUN_FORCE);
var properties = { var properties = {
type: 'Sphere', type: 'Sphere',
color: BALL_COLOR, color: BALL_COLOR,
@ -148,8 +149,10 @@
var frontOffset = Vec3.multiply(frontVector, GUN_TIP_FWD_OFFSET); var frontOffset = Vec3.multiply(frontVector, GUN_TIP_FWD_OFFSET);
var upVector = Quat.getRight(properties.rotation); var upVector = Quat.getRight(properties.rotation);
var upOffset = Vec3.multiply(upVector, GUN_TIP_UP_OFFSET); var upOffset = Vec3.multiply(upVector, GUN_TIP_UP_OFFSET);
var gunTipPosition = Vec3.sum(properties.position, frontOffset); var gunTipPosition = Vec3.sum(properties.position, frontOffset);
gunTipPosition = Vec3.sum(gunTipPosition, upOffset); gunTipPosition = Vec3.sum(gunTipPosition, upOffset);
return gunTipPosition; return gunTipPosition;
}, },