Search Unity

3ds bones rotation by unity

Discussion in 'Scripting' started by Mr_Albert, Jul 15, 2017.

  1. Mr_Albert

    Mr_Albert

    Joined:
    Apr 28, 2017
    Posts:
    25
    Hello everybody... I have a new question.


    I would like to roteate the bones of the player (biped) by a "ghost object"..

    I think I can figure it out with an image:



    now... the idea is this:

    Code (CSharp):
    1.  
    2. public void Task_BonesController_onstart()
    3.        {
    4.  
    5.            // Create a main container
    6.            GetVar.Dummy_Ribs = new GameObject("DummyOf["+GetVar.RibsBone.transform.name+"]");
    7.            GetVar.Dummy_Ribs.transform.parent = GetVar.ModelsGroup.transform;
    8.            GetVar.Dummy_Ribs.transform.rotation = GetVar.ModelsGroup.transform.root.rotation;
    9.  
    10.           // Create a fake bones
    11.            GetVar.FakeBones_Ribs = new GameObject("FakeBonesOf["+GetVar.RibsBone.transform.name+"]");
    12.            GetVar.FakeBones_Ribs.transform.parent = GetVar.Dummy_Ribs.transform;
    13.            GetVar.FakeBones_Ribs.transform.position = GetVar.Dummy_Ribs.transform.position;
    14.            GetVar.FakeBones_Ribs.transform.localRotation = GetVar.RibsBone.transform.localRotation;
    15.  
    16.        }
    17.  

    Code (CSharp):
    1.  
    2. public void Task_BonesController_onupdate()
    3.        {
    4.  
    5.               //update fake bones equal to real bones
    6.                GetVar.FakeBones_Ribs.transform.localRotation    = GetVar.RibsBone.transform.localRotation;
    7.  
    8.                //update position of dummy equale to bones position
    9.                GetVar.Dummy_Ribs.transform.position = GetVar.RibsBone.transform.position;
    10.  
    11.                //update rotation of dummy whit the target
    12.                Vector3 RibsToTargetDirection =
    13.                new Vector3
    14.                (
    15.                    (GetVar.CameraTarget.transform.position.y - GetVar.Dummy_Ribs.transform.position.y),    //X//
    16.                    (GetVar.CameraTarget.transform.position.x - GetVar.Dummy_Ribs.transform.position.x),    //Y//
    17.                    (GetVar.CameraTarget.transform.position.z - GetVar.Dummy_Ribs.transform.position.z)       //Z//
    18.                    
    19.                );
    20.                GetVar.Dummy_Ribs.transform.rotation = Quaternion.Lerp( GetVar.Dummy_Ribs.transform.rotation, Quaternion.LookRotation(RibsToTargetDirection), Time.deltaTime * GetVar.RibsSpeed );
    21.  
    22.                //update the bones equal fake bones
    23.                GetVar.RibsBone.transform.localRotation = GetVar.FakeBones_Ribs.transform.localRotation;
    24.  
    25.  
    26.       }
    27.  
    The proble is this:
    I can see the fake bones roteate with the container ... but its values do not change and, therefore, nothing is transferred to the true bones.

    What can I do then? Does anyone know some method?

    thanks...