feat: follow camera keeps constant distance to the duck
Browse files
rl.js
CHANGED
|
@@ -356,15 +356,20 @@ resize();
|
|
| 356 |
// The rig's root already applies the MJCF Z-up -> three Y-up fix, so the
|
| 357 |
// trunk group can take the freejoint pose in raw MJCF coordinates.
|
| 358 |
const _target = new THREE.Vector3();
|
|
|
|
| 359 |
function syncRig() {
|
| 360 |
const qpos = data.qpos;
|
| 361 |
trunkGroup.position.set(qpos[0], qpos[1], qpos[2]);
|
| 362 |
trunkGroup.quaternion.set(qpos[4], qpos[5], qpos[6], qpos[3]);
|
| 363 |
for (let j = 0; j < NUM_JOINTS; j++) setJoint(rig, JOINT_NAMES[j], qpos[qposAdr[j]]);
|
| 364 |
-
//
|
| 365 |
-
//
|
|
|
|
|
|
|
| 366 |
_target.set(qpos[0], qpos[2], -qpos[1]);
|
| 367 |
-
controls.target.
|
|
|
|
|
|
|
| 368 |
}
|
| 369 |
|
| 370 |
// Quack: a quick jaw flap on every mode/colour change. The jaw isn't a
|
|
|
|
| 356 |
// The rig's root already applies the MJCF Z-up -> three Y-up fix, so the
|
| 357 |
// trunk group can take the freejoint pose in raw MJCF coordinates.
|
| 358 |
const _target = new THREE.Vector3();
|
| 359 |
+
const _follow = new THREE.Vector3();
|
| 360 |
function syncRig() {
|
| 361 |
const qpos = data.qpos;
|
| 362 |
trunkGroup.position.set(qpos[0], qpos[1], qpos[2]);
|
| 363 |
trunkGroup.quaternion.set(qpos[4], qpos[5], qpos[6], qpos[3]);
|
| 364 |
for (let j = 0; j < NUM_JOINTS; j++) setJoint(rig, JOINT_NAMES[j], qpos[qposAdr[j]]);
|
| 365 |
+
// Follow cam: ease the orbit target toward the trunk and translate the
|
| 366 |
+
// camera by the same delta, so the camera-to-duck distance and viewing
|
| 367 |
+
// angle stay constant while the duck walks. Mouse orbit/zoom still work:
|
| 368 |
+
// they only change the (preserved) camera-target offset.
|
| 369 |
_target.set(qpos[0], qpos[2], -qpos[1]);
|
| 370 |
+
_follow.copy(_target).sub(controls.target).multiplyScalar(0.06);
|
| 371 |
+
controls.target.add(_follow);
|
| 372 |
+
camera.position.add(_follow);
|
| 373 |
}
|
| 374 |
|
| 375 |
// Quack: a quick jaw flap on every mode/colour change. The jaw isn't a
|