Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions character-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1136,31 +1136,39 @@ class LocalPlayer extends UninterpolatedPlayer {
});
}
grab(app, hand = 'left') {
const {position, quaternion} = _getSession() ?
localPlayer[hand === 'left' ? 'leftHand' : 'rightHand']
:
camera;

app.updateMatrixWorld();
app.savedRotation = app.rotation.clone();
app.startQuaternion = quaternion.clone();

const grabAction = {
type: 'grab',
hand,
instanceId: app.instanceId,
matrix: localMatrix.copy(app.matrixWorld)
.premultiply(localMatrix2.compose(position, quaternion, localVector.set(1, 1, 1)).invert())
.toArray()
};
this.addAction(grabAction);

physicsScene.disableAppPhysics(app)
if(this instanceof LocalPlayer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can player call grab when it's not local player?
  • Even though if it's the case, you can check this with different code. Please reference how it did on existing code.

let position = null, quaternion = null;

app.dispatchEvent({
type: 'grabupdate',
grab: true,
});
if(_getSession()) {
const h = this[hand === 'left' ? 'leftHand' : 'rightHand'];
position = h.position;
quaternion = h.quaternion;
} else {
position = this.position;
quaternion = camera.quaternion;
}

app.updateMatrixWorld();
app.savedRotation = app.rotation.clone();
app.startQuaternion = quaternion.clone();

const grabAction = {
type: 'grab',
hand,
instanceId: app.instanceId,
matrix: localMatrix.copy(app.matrixWorld)
.premultiply(localMatrix2.compose(position, quaternion, localVector.set(1, 1, 1)).invert())
.toArray()
};
this.addAction(grabAction);

physicsScene.disableAppPhysics(app)

app.dispatchEvent({
type: 'grabupdate',
grab: true,
});
}
}
ungrab() {
const actions = Array.from(this.getActionsState());
Expand Down
Loading