Search Unity

Question Moving a character based on world coordinates in a .csv file

Discussion in 'Scripting' started by Lumberingfan, Dec 8, 2022.

  1. Lumberingfan

    Lumberingfan

    Joined:
    Aug 16, 2022
    Posts:
    2
    Hi all,

    I'm pretty new at Unity but I'm trying to move a bunch of characters based on joint coordinates that I've got stored in several .CSV files that looks like the following.

    upload_2022-12-8_15-46-28.png etc

    I've managed to read all of the data and list it appropriately.

    My plan was to list the models corresponding joint Transform.position in the script and then in Update() attach the coordinates to each joints world position.

    as for instance

    LeftHip.position = new Vector3(playerPos[currentStep].lHip2.x, playerPos[currentStep].lHip2.y, playerPos[currentStep].lHip2.z);

    This worked partially as it would position each joint where it's supposed to be but it makes the model look like something from a horror movie.

    Any ideas what my next step could be?
    It's clear there are many issues at hand but if anyone has any idea where i can start that would be much appreciated!

    Attaching my code below and and image on how the coordinates are positioned in the data.

    Thanks
     

    Attached Files:

  2. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Looks like you have joints moving a character with no paint weights on the joints.

    Was this model rigged in a 3D app? Or how are you rigging it?
     
  3. zedz

    zedz

    Joined:
    Aug 31, 2013
    Posts:
    253
    without delving into the code, do you know how skeletons work?
    The children nodes/joints are dependant on the parents positions/rotations

    thus say for a knee -> foot 2 joints conected by a boine, you first have to calc kness position/rotation and then for the foot you have to add its new postions/roatations onto the knees ones
     
  4. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528

    With out doing the work in a 3D app to skin it, I doubt it will deform properly. It needs to have paint weights on the vertices.
     
  5. Lumberingfan

    Lumberingfan

    Joined:
    Aug 16, 2022
    Posts:
    2
    Hi,

    It's a basic free model that i rigged in Blender and used automatic weights. Should be alright as it bends correctly when in pose mode.

    From what I understand after reading up on it, I get lost somewhere in calculating the rotation of each joint. I've tried calculating the local position and using that to set the values but still not getting the results right.

    Should I use the world positions or local position to calculate the rotation and have that drive the motion?