I’m within the means of designing a threejs-based webxr engine for easy VR video games. Proper now, I’m engaged on implementing physics with cannon-es, however I’m struggling to determine tips on how to sync the participant’s physics physique with their headset place.
In my engine, every Entity is made up of two elements: VisualObj and (generally) PhysicalObj. For many entities, VisualObj is synced up with its PhysicalObj place every body.
At the moment, every body the next code is run for the Participant entity:
const pos = Digicam.getWorldPosition(new THREE.Vector3()).toArray();
const head = pos(1) + 0.1;
if (pos(1) !== 0) {
if (!Participant.PhysicalObj) {
Participant.PhysicalObj = new Objects.PPill({
radius: 0.25,
mass: 60,
peak: head,
offsetPos: (0, head / 2, 0),
fixedRotation: true
});
World.addBody(Participant.PhysicalObj);
}
Participant.PhysicalObj.place.set(pos(0), Participant.PhysicalObj.place.y, pos(2));
}
First, it creates the participant’s PhysicalObj (a capsule form) from a premade perform. After that, it merely strikes the PhysicalObj’s x and z positions to the digital camera’s world place. I believe this works for when the participant is simply strolling round in actual life, however will trigger main points down the road with participant motion.
That is the perform that every Entity has to sync its VisualObj with its PhysicalObj (if relevant):
Sync(cameraPos) {
if (!this.PhysicalObj) return;
this.VisualObj.place.copy(this.PhysicalObj.place);
this.VisualObj.quaternion.copy(this.PhysicalObj.quaternion);
if (this.isPlayer) {
const vec = new THREE.Vector3(cameraPos.x, 0, cameraPos.z);
this.VisualObj.place.sub(vec);
}
}
If the Entity in query is Participant, then it offsets itself by the digital camera’s native place, to stop a suggestions loop (as a result of Digicam is a baby of Participant.VisualObj).
My query is that this: Is there a greater method to transfer the participant’s PhysicalObj to the digital camera’s place, somewhat than teleporting? Would making use of the drive / impulse essential to get the physique to the digital camera’s world place, and even altering its velocity to get it there, work higher? I believe it’s essential that the PhysicalObj comply with the digital camera’s worldposition, so the participant can’t clip by means of partitions by strolling round in actual life.
Any assist can be a lot appreciated, I’ve been caught on this for fairly some time.