Spacetime-Meta / spacetime-sdk

The spacetime-sdk is a turnkey virtual environment package for building in the Spacetime Metaverse
https://www.spacetimemeta.io/metaverse/spawn-planet
MIT License
11 stars 2 forks source link

Optimize avatar rotation #59

Closed Liquid-Blocks closed 2 years ago

Liquid-Blocks commented 2 years ago

This issue is a following of the issue #49 Character face walking direction

The closing message on issues 49:

As shown in the image below, the input catching logic is duplicated between the PlayerLocal.update and AvatarController.rotateFaceDirection.

image

Ideally, to optimize the update loop, we would:

  1. Catch the user input only in the PlayerLocal.
  2. Execute the logic to find the new rotation inside PlayerLocal.update
  3. Adjust the capsules rotation using the attribute THREE.Object3D.quaternion from its parent.
  4. Pass the quaternion to the AvatarController as an argument of AvatarController.update
  5. Then the AvatarController would only copy the capsules facing rotations using AvatarController.applyQuaternion, inherited from its THREE.Object3D parent.

codeeMadness commented 2 years ago

Hi @Liquid-Blocks,

I still don't know how to use "applyQuaternion" as your suggestion. Did try, but the model still not rotate. Please help to take a look on my branch, and give any further advise. It would be much appreciate.

Liquid-Blocks commented 2 years ago

@codeeMadness No problem, I will open the branch and take a look, thank you

Liquid-Blocks commented 2 years ago

Hi @codeeMadness , I have solved the payer rotation in a new branch that I merged into develop in PR #70,

The final solution uses the horizontal velocity to find the facing rotation.