content/hifi-content/DomainContent/Welcome Area/Scripts/createTetherball.js
2022-02-13 22:49:05 +01:00

149 lines
5 KiB
JavaScript

//
// Tetherball!
//
// Derived by Thijs Wenker from a script by Caitlyn Meeks which was derived from a script by Seth Alves on 2016-7-05
// Copyright 2016 High Fidelity, Inc.
//
// Makes a tetherball that responds to collisions.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
//
"use strict";
/*jslint vars: true*/
//var Overlays, Entities, Controller, Vec3, SCRIPT_IMPORT_PROPERTIES; // Referenced globals provided by High Fidelity.
var polePosition = SCRIPT_IMPORT_PROPERTIES.polePosition;
// Slightly out of the pole, to stop jitter from happening
var ballPosition = Vec3.sum(polePosition, {
x: 0.25,
y: -1.2,
z: 0.0
});
var ballID = Entities.addEntity({
type: "Model",
modelURL: "http://hifi-content.s3.amazonaws.com/Examples%20Content/production/marblecollection/Star.fbx",
name: "Tetherball",
shapeType: "Sphere",
position: ballPosition,
dimensions: {
x: 0.3,
y: 0.3,
z: 0.3
},
gravity: {
x: 0.0,
y: -9.8,
z: 0.0
},
damping: 0.3,
angularDamping: 0.1,
density: 300,
restitution: 0.5,
dynamic: true
});
var pointToOffsetFrom = Vec3.sum(polePosition, {
x: 0.0,
y: 0.8,
z: 0.0
});
Entities.addAction("offset", ballID, {
pointToOffsetFrom: pointToOffsetFrom,
linearDistance: 2.0,
linearTimeScale: 0.1
});
var paddle1Position = Vec3.sum(polePosition, {
x: 0.0,
y: -1.4,
z: 0.25
});
Entities.addEntity( {
"clientOnly": 0,
"compoundShapeURL": "http://hifi-content.s3.amazonaws.com/Examples%20Content/production/paddleball/squashRacket_phys.obj",
"created": "2016-07-05T20:29:07Z",
"density": 10000,
"dimensions": {
"x": 0.21033146977424622,
"y": 0.81737208366394043,
"z": 0.023639317601919174
},
"gravity": {
"x": 0,
"y": -9.8000001907348633,
"z": 0
},
"dynamic": 1,
"id": "{6d4794e5-fe52-4004-bc66-520a76334e2c}",
"modelURL": "http://hifi-content.s3.amazonaws.com/Examples%20Content/production/paddleball/squashRacket_3_VR.fbx",
"name": "Squash Racket",
"owningAvatarID": "{00000000-0000-0000-0000-000000000000}",
"queryAACube": {
"scale": 0.84433126449584961,
"x": -0.4221656322479248,
"y": -0.4221656322479248,
"z": -0.4221656322479248
},
"position": paddle1Position,
"rotation": {
"w": 0.98437130451202393,
"x": -1.7827005649451166e-05,
"y": -0.17610554397106171,
"z": -9.9647018942050636e-05
},
"shapeType": "compound",
"type": "Model",
"userData": "{\"grabbableKey\":{\"invertSolidWhileHeld\":true},\"wearable\":{\"joints\":{\"RightHand\":[{\"x\":0.2982635498046875,\"y\":0.22826004028320312,\"z\":0.06467056274414062},{\"x\":-0.13706755638122559,\"y\":-0.12130661308765411,\"z\":0.4720178544521332,\"w\":-0.8623783588409424}],\"LeftHand\":[{\"x\":-0.1986083984375,\"y\":0.2963275909423828,\"z\":0.14059829711914062},{\"x\":0.19712552428245544,\"y\":-0.07430736720561981,\"z\":0.28353533148765564,\"w\":0.9355360269546509}]}}}"
});
paddle2Position = Vec3.sum(polePosition, {
x: 0.0,
y: -1.4,
z: -0.25
});
Entities.addEntity( {
"clientOnly": 0,
"compoundShapeURL": "http://hifi-content.s3.amazonaws.com/Examples%20Content/production/paddleball/squashRacket_phys.obj",
"created": "2016-07-05T20:29:07Z",
"density": 10000,
"dimensions": {
"x": 0.21033146977424622,
"y": 0.81737208366394043,
"z": 0.023639317601919174
},
"gravity": {
"x": 0,
"y": -9.8000001907348633,
"z": 0
},
"dynamic": 1,
"id": "{6d4794e5-fe52-4004-bc66-520a76334e2c}",
"modelURL": "http://hifi-content.s3.amazonaws.com/Examples%20Content/production/paddleball/squashRacket_3_VR.fbx",
"name": "Squash Racket",
"owningAvatarID": "{00000000-0000-0000-0000-000000000000}",
"queryAACube": {
"scale": 0.84433126449584961,
"x": -0.4221656322479248,
"y": -0.4221656322479248,
"z": -0.4221656322479248
},
"position": paddle2Position,
"rotation": {
"w": 0.98437130451202393,
"x": -1.7827005649451166e-05,
"y": -0.17610554397106171,
"z": -9.9647018942050636e-05
},
"shapeType": "compound",
"type": "Model",
"userData": "{\"grabbableKey\":{\"invertSolidWhileHeld\":true},\"wearable\":{\"joints\":{\"RightHand\":[{\"x\":0.2982635498046875,\"y\":0.22826004028320312,\"z\":0.06467056274414062},{\"x\":-0.13706755638122559,\"y\":-0.12130661308765411,\"z\":0.4720178544521332,\"w\":-0.8623783588409424}],\"LeftHand\":[{\"x\":-0.1986083984375,\"y\":0.2963275909423828,\"z\":0.14059829711914062},{\"x\":0.19712552428245544,\"y\":-0.07430736720561981,\"z\":0.28353533148765564,\"w\":0.9355360269546509}]}}}"
});