49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
(function () {
|
|
|
|
var GRAVITY = {x: 0, y: -6, z: 0};
|
|
var VELOCITY_MULTIPLIER = 44;
|
|
var VELOCITY_BOOST = 1;
|
|
var CLICK_RESET_TIME = 1000;
|
|
var clicked = false;
|
|
var _entityID;
|
|
|
|
function popDie(entityID) {
|
|
if (!clicked) {
|
|
var entityProps = Entities.getEntityProperties(entityID, ["position", "velocity","angularVelocity",]);
|
|
var velocityToSet = Vec3.normalize(Vec3.subtract(entityProps["position"], MyAvatar.position));
|
|
if (velocityToSet.y < 0) {
|
|
velocityToSet.y = velocityToSet.y / -1;
|
|
}
|
|
velocityToSet.y += VELOCITY BOOST;
|
|
var velocityToSet2 = Vec3.multiply(VELOCITY_MULTIPLIER, velocityToSet);
|
|
Entities.editEntity(entityID, {angularVelocity: velocityToSet2});
|
|
clicked = true;
|
|
Script.setTimeout(function () {
|
|
clicked = false;
|
|
}, CLICK_RESET_TIME);
|
|
}
|
|
}
|
|
|
|
this.stopFarTrigger = function (entityID) {
|
|
popDie(entityID);
|
|
};
|
|
|
|
this.stopNearTrigger = function (entityID) {
|
|
popDie(entityID);
|
|
};
|
|
|
|
this.clickReleaseOnEntity = function (entityID, mouseEvent) {
|
|
if (mouseEvent.isLeftButton) {
|
|
popDie(entityID);
|
|
}
|
|
};
|
|
|
|
this.preload = function (entityID) {
|
|
this.entityID = entityID;
|
|
_entityID = entityID;
|
|
Entities.editEntity(this.entityID, {
|
|
dynamic: true,
|
|
gravity: GRAVITY,
|
|
})
|
|
}
|
|
});
|