Skip to content

Commit

Permalink
User avatar sticks to moving surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusLongmuir committed Jan 17, 2024
1 parent 1e55576 commit 44b0527
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 111 deletions.
6 changes: 3 additions & 3 deletions packages/3d-web-client-core/src/camera/CameraManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ export class CameraManager {
this.camera.position,
this.target.clone().sub(this.camera.position).normalize(),
);
const minimumDistance = this.collisionsManager.raycastFirstDistance(this.rayCaster.ray);
const firstRaycastHit = this.collisionsManager.raycastFirst(this.rayCaster.ray);
const cameraToPlayerDistance = this.camera.position.distanceTo(this.target);

if (minimumDistance !== null && minimumDistance <= cameraToPlayerDistance) {
this.targetDistance = cameraToPlayerDistance - minimumDistance;
if (firstRaycastHit !== null && firstRaycastHit[0] <= cameraToPlayerDistance) {
this.targetDistance = cameraToPlayerDistance - firstRaycastHit[0];
this.distance = this.targetDistance;
} else {
this.targetDistance += (this.desiredDistance - this.targetDistance) * this.dampingFactor * 4;
Expand Down
10 changes: 5 additions & 5 deletions packages/3d-web-client-core/src/character/CharacterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ export class CharacterManager {
this.localCharacter.speakingIndicator?.setSpeaking(this.speakingCharacters.get(this.id)!);
}

this.localController.update();
if (this.timeManager.frame % 2 === 0) {
this.sendUpdate(this.localController.networkState);
}

this.cameraOffsetTarget = this.cameraManager.targetDistance <= 0.4 ? 0.13 : 0;
this.cameraOffset += ease(this.cameraOffsetTarget, this.cameraOffset, 0.1);
const targetOffset = new Vector3(0, 0, this.cameraOffset);
targetOffset.add(this.headTargetOffset);
targetOffset.applyQuaternion(this.localCharacter.quaternion);
this.cameraManager.setTarget(targetOffset.add(this.localCharacter.position));

this.localController.update();
if (this.timeManager.frame % 2 === 0) {
this.sendUpdate(this.localController.networkState);
}

for (const [id, update] of this.clientStates) {
if (this.remoteCharacters.has(id) && this.speakingCharacters.has(id)) {
const character = this.remoteCharacters.get(id);
Expand Down
Loading

0 comments on commit 44b0527

Please sign in to comment.