Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Simon1059770342 opened this issue Apr 15, 2022 · 6 comments
Open

Comments

@Simon1059770342
Copy link

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!

@NikLever
Copy link
Owner

NikLever commented Apr 16, 2022 via email

@Simon1059770342
Copy link
Author

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."?

@NikLever
Copy link
Owner

NikLever commented Apr 16, 2022 via email

@Simon1059770342
Copy link
Author

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);

@NikLever
Copy link
Owner

NikLever commented Apr 17, 2022 via email

@Simon1059770342
Copy link
Author

THX Nik!That's quiet clear Now!

Sorry for the endless question, Hope you dont mind!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants