mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
added userData manipulations to grab script
This commit is contained in:
parent
cd1dac50ad
commit
fa42334430
1 changed files with 31 additions and 4 deletions
|
@ -11,9 +11,13 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
Script.include("https://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js");
|
||||||
|
|
||||||
var RIGHT_HAND_CLICK = Controller.findAction("RIGHT_HAND_CLICK");
|
var RIGHT_HAND_CLICK = Controller.findAction("RIGHT_HAND_CLICK");
|
||||||
var rightTriggerAction = RIGHT_HAND_CLICK;
|
var rightTriggerAction = RIGHT_HAND_CLICK;
|
||||||
|
|
||||||
|
var GRAB_USER_DATA_KEY = "grabKey";
|
||||||
|
|
||||||
var LEFT_HAND_CLICK = Controller.findAction("LEFT_HAND_CLICK");
|
var LEFT_HAND_CLICK = Controller.findAction("LEFT_HAND_CLICK");
|
||||||
var leftTriggerAction = LEFT_HAND_CLICK;
|
var leftTriggerAction = LEFT_HAND_CLICK;
|
||||||
|
|
||||||
|
@ -37,7 +41,7 @@ var INTERSECT_COLOR = {
|
||||||
blue: 10
|
blue: 10
|
||||||
};
|
};
|
||||||
|
|
||||||
var GRAB_RADIUS = 2;
|
var GRAB_RADIUS = 0.5;
|
||||||
|
|
||||||
var GRAB_COLOR = {
|
var GRAB_COLOR = {
|
||||||
red: 250,
|
red: 250,
|
||||||
|
@ -154,7 +158,6 @@ controller.prototype.attemptMove = function() {
|
||||||
|
|
||||||
var newPosition = Vec3.sum(handPosition, Vec3.multiply(direction, this.distanceToEntity))
|
var newPosition = Vec3.sum(handPosition, Vec3.multiply(direction, this.distanceToEntity))
|
||||||
this.distanceHolding = true;
|
this.distanceHolding = true;
|
||||||
//TO DO : USE SPRING ACTION UPDATE FOR MOVING
|
|
||||||
if (this.actionID === null) {
|
if (this.actionID === null) {
|
||||||
this.actionID = Entities.addAction("spring", this.grabbedEntity, {
|
this.actionID = Entities.addAction("spring", this.grabbedEntity, {
|
||||||
targetPosition: newPosition,
|
targetPosition: newPosition,
|
||||||
|
@ -184,7 +187,10 @@ controller.prototype.hidePointer = function() {
|
||||||
|
|
||||||
|
|
||||||
controller.prototype.letGo = function() {
|
controller.prototype.letGo = function() {
|
||||||
Entities.deleteAction(this.grabbedEntity, this.actionID);
|
if (this.grabbedEntity && this.actionID) {
|
||||||
|
this.deactivateEntity(this.grabbedEntity);
|
||||||
|
Entities.deleteAction(this.grabbedEntity, this.actionID);
|
||||||
|
}
|
||||||
this.grabbedEntity = null;
|
this.grabbedEntity = null;
|
||||||
this.actionID = null;
|
this.actionID = null;
|
||||||
this.distanceHolding = false;
|
this.distanceHolding = false;
|
||||||
|
@ -264,11 +270,29 @@ controller.prototype.checkForInRangeObject = function() {
|
||||||
if (grabbedEntity === null) {
|
if (grabbedEntity === null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
//We are grabbing an entity, so let it know we've grabbed it
|
||||||
this.grabbedEntity = grabbedEntity;
|
this.grabbedEntity = grabbedEntity;
|
||||||
|
this.activateEntity(this.grabbedEntity);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
controller.prototype.activateEntity = function(entity) {
|
||||||
|
var data = {
|
||||||
|
activated: true,
|
||||||
|
avatarId: MyAvatar.sessionUUID
|
||||||
|
};
|
||||||
|
setEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.prototype.deactivateEntity = function(entity) {
|
||||||
|
var data = {
|
||||||
|
activated: false,
|
||||||
|
avatarId: null
|
||||||
|
};
|
||||||
|
setEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, data);
|
||||||
|
}
|
||||||
|
|
||||||
controller.prototype.onActionEvent = function(action, state) {
|
controller.prototype.onActionEvent = function(action, state) {
|
||||||
if (this.pullAction === action && state === 1) {
|
if (this.pullAction === action && state === 1) {
|
||||||
|
@ -293,7 +317,9 @@ controller.prototype.onActionEvent = function(action, state) {
|
||||||
|
|
||||||
controller.prototype.cleanup = function() {
|
controller.prototype.cleanup = function() {
|
||||||
Entities.deleteEntity(this.pointer);
|
Entities.deleteEntity(this.pointer);
|
||||||
Entities.deleteAction(this.grabbedEntity, this.actionID);
|
if (this.grabbedEntity) {
|
||||||
|
Entities.deleteAction(this.grabbedEntity, this.actionID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
|
@ -314,6 +340,7 @@ function cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
||||||
Script.update.connect(update)
|
Script.update.connect(update)
|
||||||
Controller.actionEvent.connect(onActionEvent);
|
Controller.actionEvent.connect(onActionEvent);
|
Loading…
Reference in a new issue