Logging player position

I’m working on a project where I need to be able to log the players current position and the export that data out of unity, in the form of an xml, or csv file.

a log like this would be good, even a single line in a text file that keeps updating would be great… I’m attempting to then bring this data into grasshopper for rhino and actuate motors with an arduino.

I found an example here:

http://xeophin.net/en/blog/2010/05/12/writing-xml-log-files-unity-3d-using-c

unfortunately I can’t get these scripts working, can someone describe the gameobjects I would need to create/name and what to attach the script to?.. or another simpler method entirely?

I wanted to update this, got it working, I’m using the xml _GameSaveLoad script on the wiki to save the data, I removed the gui functions and create an xml file in function update() so, that’s every frame a new xml is created, this is then parsed by a grasshopper definition running using the ghowl xml parser, the x, y, and z values are then sent to an arduino to create havoc. :slight_smile:

so, how can I create a function to create a new xml every 1 second, instead of using update()

I’m not a huge fan of xml myself - its wayyy too paddey to use for something like this! Seeing as a position is just a number and kinda always will be, you’d be much better off going for some type of csv file, or better, directly working with float bytes (12 bytes per position and would be about as compact as it could possibly get, which would be important if your logging the position every second :slight_smile: ).
To do this I would suggest building up an array of Vector3’s, and then when the player quits or logs out build the file and either send it to a server via WWW or dump it straight into a file (requires using C# for that bit!), as constructing it every second would be pretty hefty on performance. Has the file got to go to a remote server or stay on the players pc?

Example on the way :slight_smile:

thanks for the info, unfortunately I need the file to be generated during runtime so I can feed it at the same time into grasshopper/arduino/motor control.

I really dont even need a log, just 1 updating line with x,y,z.

The most recent position in a file? :slight_smile:

yes! :slight_smile:

Here we go! This lil demo saves the position in a lil file called log.txt - its not human readable though, so I’ve made a small function in there that also loads it back into the position again. It goes by sticking the x/y/z values directly into the file so its lots faster than xml and shouldn’t affect performance (could probably run it every 0.1 seconds or so :slight_smile: ).

If you open up this lil project and go to the scene in there and hit play, a random cube should start moving and it’ll log it’s position into the file. If you hit the Load File button itll then turn that files contents back into a position again :slight_smile:

519582–18437–$positionLog.zip (1.13 MB)

To get it to work for any item, make sure you’ve got the fileMaker script in a folder called plugins, and attach ‘logit.js’ to the object you want track :slight_smile:

Edit: logit.js auto moves the object its stuck to so you’d need to comment out this part:

transform.position.x+=0.5*Time.deltaTime;
transform.position.y+=0.5*Time.deltaTime;
transform.position.z-=0.5*Time.deltaTime;

If the raw bytes in the file aren’t too suitable then csv would still be much better than xml :slight_smile:

LukeB: I installed your little script etc, and I can read from my console that it prints my coordinates out.
When I open my log.txt it looks really weird.
Is it possible to have plain numbers printed in the file?
I would like to store various data in a text file and then run it through some plotting tools to do some stats on the collected data.