store positional data into a csv file

I am currently working on a school project where I’ll be using motion capture and unity. It’s made for the elderly to improve their cognitive and motoric functions. I want unity to be able to record their movements into a csv file to see how well they are doing. I want the x, y and z co-ordinates recorded against time in excel.

I’m using perception neuron for my motion capture which have a total of 32 sensors. The 3D model in unity has 32 different parts/limbs that move, including the fingers. I added a picture of it here:

Now in this code i cant seem to get the co-ordinates of a limb (i’m just trying to get the coordinates of a single limb for now). I tried splitting Vector3 into x, y, z coordinates to get separate co-ordinates and also because i want the values to be float too but it does not seem to work could anyone help me with this?

Here’s my code:

using UnityEngine;
using System.Collections.Generic;
using System;
using System.IO;

public class Test : MonoBehaviour
{
    float timer = 100.0f;
    public TestSO so ;
    StreamWriter motionData;

    

    public void Start()
    {

       

        string fullFilename = @"C:\Users\Administrator\Desktop\CsvPlz.csv";

        motionData = new StreamWriter(fullFilename, true);

        InvokeRepeating("wolf", 0.0f, 0.5f);
       
    }

    void wolf()
    {

        timer += Time.deltaTime;
        string delimiter = ", ";

        
        var position : Vector3;

        var x: float = position[0];
        var y : float = position[1];
        var z : float = position[2];

        if (timer > 1.0f)
        {
            timer -= 1.0f;            
            string dataText = ("{1}",x) + delimiter + ("{2}", y) + delimiter + ("{3}", z);
            motionData.WriteLine(dataText);
        }

        motionData.Close();

    }

   
}

Uhm where do you actually reference your limbs? Currently you seem to create a local position variable which you never initialize and then read it’s values. This makes no sense. Apart from this your code would never compile. You’re mixing C# with UnityScript. UnityScript is a deprecated language anyways.

Furthermore you have another logical error in your code. You open a file stream in Start but you’re closing it inside your “wolf” callback. That means when wolf is called the second time the stream is closed and you can no longer write to the file.

Second logic error is that you use InvokeRepeating with a repeat rate of 2 calls per second, but inside the callback you use Time.deltaTime to increase your timer. This makes no sense at all as deltaTime only makes sense when used every frame.

Finally this line makes no sense:

string dataText = ("{1}",x) + delimiter + ("{2}", y) + delimiter + ("{3}", z);

This looks like you wanted to use something like string.Format but as it’s written now it just makes no sense and wouldn’t compile.

We don’t know how your skeleton structure looks like or how you want to translate the hierachical structure into a linear list. You have to provide more information on your setup and how the final data should look like. Do your bones / limbs have any names? Do you only want the worldspace positions of each limb?