Skip to content

Commit 0c956b8

Browse files
committed
optionally use world position when calculating hand distance for stretchable component
1 parent 0646935 commit 0c956b8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

reaction_components/stretchable.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ AFRAME.registerComponent('stretchable', inherit(base, {
88
schema: {
99
usePhysics: {default: 'ifavailable'},
1010
invert: {default: false},
11-
physicsUpdateRate: {default: 100}
11+
physicsUpdateRate: {default: 100},
12+
useWorldSpaceCoordinates: {type: "bool", default: false}
1213
},
1314
init: function () {
1415
this.STRETCHED_STATE = 'stretched'
@@ -37,8 +38,13 @@ AFRAME.registerComponent('stretchable', inherit(base, {
3738
tick: function (time, timeDelta) {
3839
if (!this.stretched) { return }
3940
this.scale.copy(this.el.getAttribute('scale'))
40-
this.handPos.copy(this.stretchers[0].getAttribute('position'))
41-
this.otherHandPos.copy(this.stretchers[1].getAttribute('position'))
41+
if (this.data.useWorldSpaceCoordinates) {
42+
this.stretchers[0].object3D.getWorldPosition(this.handPos)
43+
this.stretchers[1].object3D.getWorldPosition(this.otherHandPos)
44+
} else {
45+
this.handPos.copy(this.stretchers[0].getAttribute('position'))
46+
this.otherHandPos.copy(this.stretchers[1].getAttribute('position'))
47+
}
4248
const currentStretch = this.handPos.distanceTo(this.otherHandPos)
4349
let deltaStretch = 1
4450
if (this.previousStretch !== null && currentStretch !== 0) {

0 commit comments

Comments
 (0)