pepefrog69
pepefrog69

Reputation: 27

Extracting separate co-ordinates of a game object

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-ordinate recorded against time in excel.

I'm using perception neuron for my motion capture which has 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:

enter image description here

Now in this code, I can't seem to get the coordinates of a limb (i'm just trying to get the coordinates of a single limb for now). I struggling with trying to extract the gameobject's coordinates. But I tried splitting Vector3 into x, y, z coordinates to get separate coordinates 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();
    }
}

Upvotes: 0

Views: 98

Answers (1)

KYL3R
KYL3R

Reputation: 4073

Change

var position : Vector3;

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

To

Vector3 position = Vector3.One;

float x = position.x;
float y = position.y;
float z = position.z;

the variables x y and z are optional, as Vector3 already contains floats. You could just use position.x directly.

Upvotes: 2

Related Questions