mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
Merge pull request #6046 from sethalves/flip-you-for-real
add a userdata flag to toggle ignoreForCollisions while holding an entity
This commit is contained in:
commit
69d6e5d298
2 changed files with 28 additions and 21 deletions
|
@ -84,6 +84,11 @@ var STATE_RELEASE = 10;
|
||||||
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js
|
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js
|
||||||
var GRAB_USER_DATA_KEY = "grabKey"; // shared with grab.js
|
var GRAB_USER_DATA_KEY = "grabKey"; // shared with grab.js
|
||||||
|
|
||||||
|
var DEFAULT_GRABBABLE_DATA = {
|
||||||
|
grabbable: true,
|
||||||
|
invertSolidWhileHeld: false
|
||||||
|
};
|
||||||
|
|
||||||
function getTag() {
|
function getTag() {
|
||||||
return "grab-" + MyAvatar.sessionUUID;
|
return "grab-" + MyAvatar.sessionUUID;
|
||||||
}
|
}
|
||||||
|
@ -254,10 +259,6 @@ function MyController(hand, triggerAction) {
|
||||||
|
|
||||||
this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
|
this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
|
||||||
|
|
||||||
var defaultGrabbableData = {
|
|
||||||
grabbable: true
|
|
||||||
};
|
|
||||||
|
|
||||||
var intersection = Entities.findRayIntersection(pickRay, true);
|
var intersection = Entities.findRayIntersection(pickRay, true);
|
||||||
if (intersection.intersects && intersection.properties.locked === 0) {
|
if (intersection.intersects && intersection.properties.locked === 0) {
|
||||||
// the ray is intersecting something we can move.
|
// the ray is intersecting something we can move.
|
||||||
|
@ -265,7 +266,7 @@ function MyController(hand, triggerAction) {
|
||||||
var intersectionDistance = Vec3.distance(handControllerPosition, intersection.intersection);
|
var intersectionDistance = Vec3.distance(handControllerPosition, intersection.intersection);
|
||||||
this.grabbedEntity = intersection.entityID;
|
this.grabbedEntity = intersection.entityID;
|
||||||
|
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, defaultGrabbableData);
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA);
|
||||||
if (grabbableData.grabbable === false) {
|
if (grabbableData.grabbable === false) {
|
||||||
this.grabbedEntity = null;
|
this.grabbedEntity = null;
|
||||||
return;
|
return;
|
||||||
|
@ -298,7 +299,7 @@ function MyController(hand, triggerAction) {
|
||||||
|
|
||||||
for (i = 0; i < nearbyEntities.length; i++) {
|
for (i = 0; i < nearbyEntities.length; i++) {
|
||||||
|
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, nearbyEntities[i], defaultGrabbableData);
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, nearbyEntities[i], DEFAULT_GRABBABLE_DATA);
|
||||||
if (grabbableData.grabbable === false) {
|
if (grabbableData.grabbable === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -690,24 +691,24 @@ function MyController(hand, triggerAction) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.activateEntity = function(entityID, grabbedProperties) {
|
this.activateEntity = function(entityID, grabbedProperties) {
|
||||||
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, entityID, DEFAULT_GRABBABLE_DATA);
|
||||||
|
var invertSolidWhileHeld = grabbableData["invertSolidWhileHeld"];
|
||||||
var data = getEntityCustomData(GRAB_USER_DATA_KEY, entityID, {});
|
var data = getEntityCustomData(GRAB_USER_DATA_KEY, entityID, {});
|
||||||
data["activated"] = true;
|
data["activated"] = true;
|
||||||
data["avatarId"] = MyAvatar.sessionUUID;
|
data["avatarId"] = MyAvatar.sessionUUID;
|
||||||
data["refCount"] = data["refCount"] ? data["refCount"] + 1 : 1;
|
data["refCount"] = data["refCount"] ? data["refCount"] + 1 : 1;
|
||||||
// zero gravity and set ignoreForCollisions to true, but in a way that lets us put them back, after all grabs are done
|
// zero gravity and set ignoreForCollisions in a way that lets us put them back, after all grabs are done
|
||||||
if (data["refCount"] == 1) {
|
if (data["refCount"] == 1) {
|
||||||
data["gravity"] = grabbedProperties.gravity;
|
data["gravity"] = grabbedProperties.gravity;
|
||||||
data["ignoreForCollisions"] = grabbedProperties.ignoreForCollisions;
|
data["ignoreForCollisions"] = grabbedProperties.ignoreForCollisions;
|
||||||
Entities.editEntity(entityID, {
|
var whileHeldProperties = {gravity: {x:0, y:0, z:0}};
|
||||||
gravity: {
|
if (invertSolidWhileHeld) {
|
||||||
x: 0,
|
whileHeldProperties["ignoreForCollisions"] = ! grabbedProperties.ignoreForCollisions;
|
||||||
y: 0,
|
}
|
||||||
z: 0
|
Entities.editEntity(entityID, whileHeldProperties);
|
||||||
},
|
|
||||||
ignoreForCollisions: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
setEntityCustomData(GRAB_USER_DATA_KEY, entityID, data);
|
setEntityCustomData(GRAB_USER_DATA_KEY, entityID, data);
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.deactivateEntity = function(entityID) {
|
this.deactivateEntity = function(entityID) {
|
||||||
|
@ -742,4 +743,4 @@ function cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
|
|
|
@ -29,8 +29,9 @@ var IDENTITY_QUAT = {
|
||||||
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with handControllerGrab.js
|
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with handControllerGrab.js
|
||||||
var GRAB_USER_DATA_KEY = "grabKey"; // shared with handControllerGrab.js
|
var GRAB_USER_DATA_KEY = "grabKey"; // shared with handControllerGrab.js
|
||||||
|
|
||||||
var defaultGrabbableData = {
|
var DEFAULT_GRABBABLE_DATA = {
|
||||||
grabbable: true
|
grabbable: true,
|
||||||
|
invertSolidWhileHeld: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -324,8 +325,7 @@ Grabber.prototype.pressEvent = function(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, pickResults.entityID, DEFAULT_GRABBABLE_DATA);
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, pickResults.entityID, defaultGrabbableData);
|
|
||||||
if (grabbableData.grabbable === false) {
|
if (grabbableData.grabbable === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -496,6 +496,8 @@ Grabber.prototype.keyPressEvent = function(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Grabber.prototype.activateEntity = function(entityID, grabbedProperties) {
|
Grabber.prototype.activateEntity = function(entityID, grabbedProperties) {
|
||||||
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, entityID, DEFAULT_GRABBABLE_DATA);
|
||||||
|
var invertSolidWhileHeld = grabbableData["invertSolidWhileHeld"];
|
||||||
var data = getEntityCustomData(GRAB_USER_DATA_KEY, entityID, {});
|
var data = getEntityCustomData(GRAB_USER_DATA_KEY, entityID, {});
|
||||||
data["activated"] = true;
|
data["activated"] = true;
|
||||||
data["avatarId"] = MyAvatar.sessionUUID;
|
data["avatarId"] = MyAvatar.sessionUUID;
|
||||||
|
@ -504,7 +506,11 @@ Grabber.prototype.activateEntity = function(entityID, grabbedProperties) {
|
||||||
if (data["refCount"] == 1) {
|
if (data["refCount"] == 1) {
|
||||||
data["gravity"] = grabbedProperties.gravity;
|
data["gravity"] = grabbedProperties.gravity;
|
||||||
data["ignoreForCollisions"] = grabbedProperties.ignoreForCollisions;
|
data["ignoreForCollisions"] = grabbedProperties.ignoreForCollisions;
|
||||||
Entities.editEntity(entityID, {gravity: {x:0, y:0, z:0}, ignoreForCollisions: true});
|
var whileHeldProperties = {gravity: {x:0, y:0, z:0}};
|
||||||
|
if (invertSolidWhileHeld) {
|
||||||
|
whileHeldProperties["ignoreForCollisions"] = ! grabbedProperties.ignoreForCollisions;
|
||||||
|
}
|
||||||
|
Entities.editEntity(entityID, whileHeldProperties);
|
||||||
}
|
}
|
||||||
setEntityCustomData(GRAB_USER_DATA_KEY, entityID, data);
|
setEntityCustomData(GRAB_USER_DATA_KEY, entityID, data);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue