NikLever/Learn-WebXR

Example 11:Difference between "this" and "player" in Player.js

Opened this issue · 6 comments

Hello, Nik! Nice course!
A difficulty has arisen after taking your course and attempting Example 11: What is the difference between "this" and "player" in Player.js?

The relevant code is as follows:
const player = this.object; const pt = this.calculatedPath[0].clone(); pt.y = player.position.y; const quaternion = player.quaternion.clone(); player.lookAt(pt); this.quaternion = player.quaternion.clone(); player.quaternion.copy(quaternion);

Why is it necessary to save "quanternion" to "player.quaternion" in the final line?

Does this imply that "player" stores quaternion in a temporary state after lookAt terget?

THX!

THX Nik! This helps a lot!
One last qusetion for your last words,
"The last step is to restore the players original quaternion. Then in the render loop we use the slerp method of the quaternion class to interpolate towards this pre-calculated quaternion.",
What's the purpose for " to interpolate towards this pre-calculated quaternion."?

THX Nik! This clear my doubt on interpolation.

Still some doubts stay.

  1. Do you mean lookAt is served for "If a character is climbing or descending we still want them to remain upright. "

If it is, I wrongly reckoned lookAt as a function for changing direction of knight from current to face target spot, which rotate around the y-axis.

And I test the code followed is work on keeping knight upright:

    const pt = this.object.position.clone();
    pt.z += 10;
    this.object.lookAt(pt);
  1. What is the purpose for "The last step is to restore the players original quaternion. " instead of just keeping the changed quaternion in players as same as this.quaternion
    this.quaternion = player.quaternion.clone();
    player.quaternion.copy(quaternion);

THX Nik!That's quiet clear Now!

Sorry for the endless question, Hope you dont mind!