AnyPortrait > Forum > How to Use

[Archive] Get the world position of a Bone after calling SetBonePosition

  • This topic has 0 replies, 1 voice, and was last updated 1 week ago by Archive AccountArchive Account.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1293
    Archive AccountArchive Account

      Q.

      I can set the bone’s position using script functions like apPortrait.SetBonePosition(apOptBone, targetPos), but I can’t get the bone’s position.
      Can I get the bone’s World Position?

      And why does the bone go back to its original position after calling SetBonePosition?

       

      A.

      The coordinate system of the Bone’s position value is AnyPortrait’s own coordinate system.
      So you can’t use the Bone’s Position value as it is.

      To get the Bone’s World coordinate in the Unity Scene, you need to use “Socket“.
      When you activate the “Socket” option, a Transform corresponding to the Socket is actually created.
      By referencing this Transform, you can know the Bone’s position and rotation value in the World coordinate system.
      And you can get the Socket by using the GetBoneSocket function in the apPortrait script.
      https://rainyrizzle.github.io/en/AdvancedManual/AD_Socket.html

      However, there is one thing to be careful about.
      If you use the SetBonePosition script and immediately after that reference the Transform value of the Socket, you will notice that the value is not applied properly.
      This is because most of the operations of AnyPortrait are performed in “LateUpdate“.

      If you called SetBonePosition function in Update, you need to reference Socket in LateUpdate of that frame after apPortrait has done most of its operations.
      Write the code referencing Socket’s position in LateUpdate, and also change the setting of “Project Settings > Script Execution Order” so that the script is executed after apPortrait.

       

      Here is the answer to your question:
      The “SetBonePosition” function only works on the frame it is called on, and then it goes back to the original state on the next frame.
      So if you want to control the bone position continuously, call the “SetBonePosition” function every frame.
      If you want to interpolate smoothly, set the value of the “weight” argument to “0 > 1 > 0”.

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top