Don't attach to joints in range when I grab

This commit is contained in:
Atlante45 2014-05-29 15:50:23 -07:00
parent 73f7390eaa
commit c7b636365c

View file

@ -88,6 +88,8 @@ function controller(wichSide) {
this.oldModelPosition;
this.oldModelRadius;
this.jointsIntersectingFronStart = [];
this.laser = Overlays.addOverlay("line3d", {
position: { x: 0, y: 0, z: 0 },
end: { x: 0, y: 0, z: 0 },
@ -142,6 +144,14 @@ function controller(wichSide) {
this.oldModelPosition = properties.position;
this.oldModelRotation = properties.modelRotation;
this.oldModelRadius = properties.radius;
this.jointsIntersectingFronStart = [];
for (var i = 0; i < jointList.length; i++) {
var distance = Vec3.distance(MyAvatar.getJointPosition(jointList[i]), this.oldModelPosition);
if (distance < this.oldModelRadius) {
this.jointsIntersectingFronStart.push(i);
}
}
}
}
@ -161,10 +171,14 @@ function controller(wichSide) {
}
}
print("closestJoint: " + jojntList[closestJointIndex]);
print("closestJoint: " + jointList[closestJointIndex]);
print("closestJointDistance (attach max distance): " + closestJointDistance + " (" + this.oldModelRadius + ")");
if (closestJointDistance < this.oldModelRadius) {
if (this.jointsIntersectingFronStart.indexOf(closestJointIndex) != -1) {
// Do nothing
} else {
print("Attaching to " + jointList[closestJointIndex]);
var jointPosition = MyAvatar.getJointPosition(jointList[closestJointIndex]);
var jointRotation = MyAvatar.getJointCombinedRotation(jointList[closestJointIndex]);
@ -179,9 +193,11 @@ function controller(wichSide) {
Models.deleteModel(this.modelID);
}
}
}
this.grabbing = false;
this.modelID.isKnownID = false;
this.jointsIntersectingFronStart = [];
}
this.checkTrigger = function () {