mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 11:13:09 +02:00
Merge pull request #5979 from imgntn/ping_pong_gun
[Script] Updates to Ping Pong Gun
This commit is contained in:
commit
0afaf84e2a
3 changed files with 35 additions and 30 deletions
|
@ -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,
|
||||||
|
@ -25,14 +25,15 @@ var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
|
||||||
var pingPongGun = Entities.addEntity({
|
var pingPongGun = Entities.addEntity({
|
||||||
type: "Model",
|
type: "Model",
|
||||||
modelURL: MODEL_URL,
|
modelURL: MODEL_URL,
|
||||||
shapeType: 'compound',
|
shapeType:'box',
|
||||||
compoundShapeURL: COLLISION_HULL_URL,
|
// shapeType: 'compound',
|
||||||
|
// compoundShapeURL: COLLISION_HULL_URL,
|
||||||
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 +41,4 @@ var pingPongGun = Entities.addEntity({
|
||||||
function cleanUp() {
|
function cleanUp() {
|
||||||
Entities.deleteEntity(pingPongGun);
|
Entities.deleteEntity(pingPongGun);
|
||||||
}
|
}
|
||||||
Script.scriptEnding.connect(cleanUp);
|
Script.scriptEnding.connect(cleanUp);
|
|
@ -21,14 +21,14 @@
|
||||||
|
|
||||||
//if the trigger value goes below this value, reload the gun.
|
//if the trigger value goes below this value, reload the gun.
|
||||||
var RELOAD_THRESHOLD = 0.95;
|
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_TIP_UP_OFFSET = 0.040;
|
||||||
var GUN_FORCE = 15;
|
var GUN_FORCE = 9;
|
||||||
var BALL_RESTITUTION = 0.6;
|
var BALL_RESTITUTION = 0.6;
|
||||||
var BALL_LINEAR_DAMPING = 0.4;
|
var BALL_LINEAR_DAMPING = 0.4;
|
||||||
var BALL_GRAVITY = {
|
var BALL_GRAVITY = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: -9.8,
|
y: -4.8,
|
||||||
z: 0
|
z: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,14 +36,14 @@
|
||||||
x: 0.04,
|
x: 0.04,
|
||||||
y: 0.04,
|
y: 0.04,
|
||||||
z: 0.04
|
z: 0.04
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
var BALL_COLOR = {
|
var BALL_COLOR = {
|
||||||
red: 255,
|
red: 255,
|
||||||
green: 255,
|
green: 255,
|
||||||
blue: 255
|
blue: 255
|
||||||
}
|
};
|
||||||
|
|
||||||
PingPongGun.prototype = {
|
PingPongGun.prototype = {
|
||||||
hand: null,
|
hand: null,
|
||||||
|
@ -68,7 +68,6 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
continueNearGrab: function() {
|
continueNearGrab: function() {
|
||||||
|
|
||||||
if (this.whichHand === null) {
|
if (this.whichHand === null) {
|
||||||
//only set the active hand once -- if we always read the current hand, our 'holding' hand will get overwritten
|
//only set the active hand once -- if we always read the current hand, our 'holding' hand will get overwritten
|
||||||
this.setWhichHand();
|
this.setWhichHand();
|
||||||
|
@ -81,10 +80,14 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
releaseGrab: function() {
|
releaseGrab: function() {
|
||||||
var _t = this;
|
var _this = this;
|
||||||
this.canShootTimeout = Script.setTimeout(function() {
|
|
||||||
_t.canShoot = false;
|
if (this.whichHand === this.hand) {
|
||||||
}, 250)
|
this.whichHand = null;
|
||||||
|
this.canShootTimeout = Script.setTimeout(function() {
|
||||||
|
_this.canShoot = false;
|
||||||
|
}, 250);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
checkTriggerPressure: function(gunHand) {
|
checkTriggerPressure: function(gunHand) {
|
||||||
|
@ -97,18 +100,20 @@
|
||||||
if (this.triggerValue < RELOAD_THRESHOLD) {
|
if (this.triggerValue < RELOAD_THRESHOLD) {
|
||||||
// print('RELOAD');
|
// print('RELOAD');
|
||||||
this.canShoot = true;
|
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"]);
|
var gunProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
|
||||||
this.shootBall(gunProperties);
|
this.shootBall(gunProperties);
|
||||||
this.canShoot = false;
|
this.canShoot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
|
||||||
shootBall: function(gunProperties) {
|
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.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,
|
||||||
|
@ -130,7 +135,7 @@
|
||||||
|
|
||||||
playSoundAtCurrentPosition: function(position) {
|
playSoundAtCurrentPosition: function(position) {
|
||||||
var audioProperties = {
|
var audioProperties = {
|
||||||
volume: 0.1,
|
volume: 0.2,
|
||||||
position: position
|
position: position
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -139,12 +144,14 @@
|
||||||
|
|
||||||
getGunTipPosition: function(properties) {
|
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
|
//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 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 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;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -457,8 +457,7 @@ function createPingPongBallGun() {
|
||||||
var pingPongGun = Entities.addEntity({
|
var pingPongGun = Entities.addEntity({
|
||||||
type: "Model",
|
type: "Model",
|
||||||
modelURL: MODEL_URL,
|
modelURL: MODEL_URL,
|
||||||
shapeType: 'compound',
|
shapeType: 'box',
|
||||||
compoundShapeURL: COLLISION_HULL_URL,
|
|
||||||
script: scriptURL,
|
script: scriptURL,
|
||||||
position: position,
|
position: position,
|
||||||
rotation: rotation,
|
rotation: rotation,
|
||||||
|
@ -468,9 +467,9 @@ function createPingPongBallGun() {
|
||||||
z: 0
|
z: 0
|
||||||
},
|
},
|
||||||
dimensions: {
|
dimensions: {
|
||||||
x: 0.67,
|
x: 0.08,
|
||||||
y: 0.14,
|
y: 0.21,
|
||||||
z: 0.09
|
z: 0.47
|
||||||
},
|
},
|
||||||
collisionsWillMove: true,
|
collisionsWillMove: true,
|
||||||
});
|
});
|
||||||
|
@ -478,8 +477,6 @@ function createPingPongBallGun() {
|
||||||
setEntityCustomData(resetKey, pingPongGun, {
|
setEntityCustomData(resetKey, pingPongGun, {
|
||||||
resetMe: true
|
resetMe: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createBasketballHoop() {
|
function createBasketballHoop() {
|
||||||
|
|
Loading…
Reference in a new issue