-
Notifications
You must be signed in to change notification settings - Fork 100
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
Comments
Hi Simon
As the code shows player is the object property of this, the instance of the Player class.
As the character sets out on a new section of the path we want to know what orientation, quaternion, would orientate the character for this leg. To get this orientation we set pt to the first node on the calculated path. We only want lookAt adjust the orientation in the y Axis. If a character is climbing or descending we still want them to remain upright. So we set pt.y to match the players current y position. Then we save the players current orientation, its quaternion property, so we can restore in a moment. Then we use lookAt to orientate the player. Now we can save the players quaternion as a property of the Player instance. 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.
Hope that helps.
Cheers Nik
Nicholas Lever, 28 Platt Lane, Dobcross, Oldham, OL3 5QD
t: 0797 370 2959 e: ***@***.***
… On 15 Apr 2022, at 09:06, Simon1059770342 ***@***.***> wrote:
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!
—
Reply to this email directly, view it on GitHub <#2>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALGSZ6Y25SDNYRWYZ3BDD63VFEPOVANCNFSM5TP35A6A>.
You are receiving this because you are subscribed to this thread.
|
THX Nik! This helps a lot! |
Hi Simon
A path is a series of points that once completed will see the player.object move from A to B. Suppose the y direction for the first leg should have the player.object on a 15 deg bearing. But currently the player is on 0 deg bearing. The code sets the quaternion to place the player.object on a 15 deg bearing, but rather than jumping to this the player will blend from 0deg to 15deg over a short time interval. That’s interpolation. For quaternion this is handled using spherical interpolation using the slerp method.
Cheers Nik
Nicholas Lever, 28 Platt Lane, Dobcross, Oldham, OL3 5QD
t: 0797 370 2959 e: ***@***.***
… On 16 Apr 2022, at 14:50, Simon1059770342 ***@***.***> wrote:
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."?
—
Reply to this email directly, view it on GitHub <#2 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALGSZ64H2AHQTC3SHO3THY3VFLARTANCNFSM5TP35A6A>.
You are receiving this because you commented.
|
THX Nik! This clear my doubt on interpolation. Still some doubts stay.
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:
|
Hi Simon
1. Try pt.y += 5. You’ll see the character lean over
2. So the orientation is changed over time not suddenly. This makes a smoother and more realistic motion.
Cheers Nik
Nicholas Lever, 28 Platt Lane, Dobcross, Oldham, OL3 5QD
t: 0797 370 2959 e: ***@***.***
… On 17 Apr 2022, at 09:31, Simon1059770342 ***@***.***> wrote:
THX Nik! This clear my doubt on interpolation.
Still some doubts stay.
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);
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);
—
Reply to this email directly, view it on GitHub <#2 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALGSZ6YXOPMQKOOKLKH7VTLVFPD7ZANCNFSM5TP35A6A>.
You are receiving this because you commented.
|
THX Nik!That's quiet clear Now! Sorry for the endless question, Hope you dont mind! |
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!
The text was updated successfully, but these errors were encountered: