- Home /
 
How to gather data and stop gathering after collision
Hi guys!
Kinda a noob question here, how do I output 100 pieces of data continually until a game object collides with another game object, or in this case the 'goal'. The idea here is that after it gathers 100 values, a counter hits and it gathers a 100 more values. It goes on and on until finally the player hits the goal.
Here's a sample code I made:
 if (!collided) {            
     if (dataPoints == 100) {
         EndWrite;
     }
 
 if (dataPoints <= 100) {
         saveData.name = saveData.name +
         Input.acceleration.x + ", " +
         Input.acceleration.y + ", " +
         Input.acceleration.z + ", ";
     }
 dataPoints++;
     }
 }
 
               So far I've managed to gather 100 values before closing the filewriter. I don't how to get the next 100 values.
I'm kinda stuck as to how to go from here. Any help is greatly appreciated!
Are you trying to generate a CSV file or string with all the acceleration values from Input in it up until a collision?
Yes I am trying to generate a file with acceleration values until a collision occurs.
I'm making a JSON file right now, but maybe making a CSV would be better. I'll be testing the CSV one for now
Answer by MaxGuernseyIII · Oct 22, 2017 at 03:13 AM
I don't know why you want to output 100 a time, per se. I would just batch them up in a list of Vector3 and then burst them all out to my file when the collection happens.
 private List<Vector3> accelerations;
 
 void Update() {
   collisions.Add(Input.acceleration);
 }
 
 // call this when you want to write all the objections
 void Output() {
   string toWrite = "";
 
   // add header stuff to toWrite
 
   foreach (var a in accelerations) {
     // append content of a however you want it to be formed
   }
 
   // add closing stuff to toWrite
 
   // output toWrite where you want it to go
 
   accelerations.Clear();
 }
 
              Thanks for the idea!
This might be a dumb question. I can somehow output accelerometer data by using this
 void Output(){
         string[] rowDataTemp = new string[3];
         rowDataTemp[0] = "x-axis";
         rowDataTemp[1] = "y-axis";
         rowDataTemp[2] = "z-axis";
         rowData.Add (rowDataTemp);
 
         rowDataTemp = new string[3];
         rowDataTemp [0] = Input.acceleration.x.ToString();
         rowDataTemp [1] = Input.acceleration.y.ToString();
         rowDataTemp [2] = Input.acceleration.z.ToString();
         rowData.Add (rowDataTemp);
 
                  but is there anyway for the rowDataTemp to stop pasting "x-axis", "y-axis", and "z-axis" after it has done it the first time?
Or meh, It does output accelerometer data already so I don't think I'd go through the trouble just to add the headers there.
Thanks for the comments!
Answer by unity_G2yrNlWYdpJKuw · Oct 21, 2017 at 04:48 PM
To detect collision you can use this : https://unity3d.com/learn/tutorials/topics/physics/detecting-collisions-oncollisionenter
Hopefully from now on you can do it by yourself because I don't really understand your question fully.
Sorry english isn't really my best language hahahaha. What I'm trying to do is output 100 acceleration values at a time until it reaches a collision to a goal object
Your answer
 
             Follow this Question
Related Questions
Saving JSON file in Android,How to save json file in android 0 Answers
Multiple Cars not working 1 Answer
Why does JsonUtility fails miserably on Android? 1 Answer
Distribute terrain in zones 3 Answers
LitJSON android problem 1 Answer