Commit 098c4aaa authored by Danial KordModanlou's avatar Danial KordModanlou

wall distance updated

parent 5d6c968e
This diff is collapsed.
...@@ -20,7 +20,7 @@ public class DataSaver : MonoBehaviour ...@@ -20,7 +20,7 @@ public class DataSaver : MonoBehaviour
//delegates //delegates
public static Func<Vector3, Vector3> sideDistance; public static Action<Vector3,Action<Vector3,float>> sideDistance;
// Start is called before the first frame update // Start is called before the first frame update
...@@ -61,11 +61,12 @@ public class DataSaver : MonoBehaviour ...@@ -61,11 +61,12 @@ public class DataSaver : MonoBehaviour
pName = menu.PlayerName; pName = menu.PlayerName;
timePassed += Time.deltaTime; //timePassed += Time.deltaTime;
Save();
// if (timePassed > 0.1)
// {
Save();
// }
} }
...@@ -83,8 +84,8 @@ public class DataSaver : MonoBehaviour ...@@ -83,8 +84,8 @@ public class DataSaver : MonoBehaviour
return; return;
} }
stable = false;
List<string[]> rowData = new List<string[]>();
var csv = new StringBuilder(); var csv = new StringBuilder();
if (!pName.Equals(curentName)) if (!pName.Equals(curentName))
{ {
...@@ -99,26 +100,28 @@ public class DataSaver : MonoBehaviour ...@@ -99,26 +100,28 @@ public class DataSaver : MonoBehaviour
*/ */
} }
Vector3 playerPos = myPlayer.transform.position;
sideDistance(playerPos, (wallPos,distanceFloat) =>
{
// You can add up the values in as many cells as you want. // You can add up the values in as many cells as you want.
if (timePassed > 0.1) string[] rowDataTemp = new string[12];
{ rowDataTemp[0] = "" + (playerPos.x - firstPos.x);// distance to first pivot
string[] rowDataTemp = new string[12]; rowDataTemp[1] = "" + (playerPos.y - firstPos.y);
rowDataTemp[0] = "" + (myPlayer.transform.position.x - firstPos.x);// distance to first pivot rowDataTemp[2] = "" + (playerPos.z - firstPos.z);
rowDataTemp[1] = "" + (myPlayer.transform.position.y - firstPos.y);
rowDataTemp[2] = "" + (myPlayer.transform.position.z - firstPos.z);
rowDataTemp[3] = ""+ myPlayer.speed; //current speed rowDataTemp[3] = ""+ myPlayer.speed; //current speed
rowDataTemp[4] = "" + pivotName; // last pivot name rowDataTemp[4] = "" + pivotName; // last pivot name
rowDataTemp[5] = "" + (myPlayer.transform.position.x - pivotPos.x);// local distance to last pivot rowDataTemp[5] = "" + (playerPos.x - pivotPos.x);// local distance to last pivot
rowDataTemp[6] = "" + (myPlayer.transform.position.y - pivotPos.y); rowDataTemp[6] = "" + (playerPos.y - pivotPos.y);
rowDataTemp[7] = ""+(myPlayer.transform.position.z - pivotPos.z); rowDataTemp[7] = ""+(playerPos.z - pivotPos.z);
if (sideDistance != null) if (sideDistance != null)
{ {
Vector3 hitPoint = sideDistance(myPlayer.transform.position); //distanceComponent hitPoint = sideDistance(myPlayer.transform.position);
rowDataTemp[8] = "" + Vector3.Distance(myPlayer.transform.position, hitPoint); rowDataTemp[8] = "" + distanceFloat;
rowDataTemp[9] = "" + hitPoint.x; rowDataTemp[9] = "" + wallPos.x;
rowDataTemp[10] = "" + hitPoint.y; rowDataTemp[10] = "" + wallPos.y;
rowDataTemp[11] = "" + hitPoint.z; rowDataTemp[11] = "" + wallPos.z;
} }
else else
{ {
...@@ -127,18 +130,13 @@ public class DataSaver : MonoBehaviour ...@@ -127,18 +130,13 @@ public class DataSaver : MonoBehaviour
rowDataTemp[10] = "None"; rowDataTemp[10] = "None";
rowDataTemp[11] = "None"; rowDataTemp[11] = "None";
} }
rowData.Add(rowDataTemp);
string newLine = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", rowDataTemp[0], rowDataTemp[1], rowDataTemp[2], rowDataTemp[3],rowDataTemp[4], string newLine = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", rowDataTemp[0], rowDataTemp[1], rowDataTemp[2], rowDataTemp[3],rowDataTemp[4],
rowDataTemp[5], rowDataTemp[6], rowDataTemp[7], rowDataTemp[8], rowDataTemp[9], rowDataTemp[10], rowDataTemp[11]); rowDataTemp[5], rowDataTemp[6], rowDataTemp[7], rowDataTemp[8], rowDataTemp[9], rowDataTemp[10], rowDataTemp[11]);
timePassed = 0; timePassed = 0;
csv.AppendLine(newLine); csv.AppendLine(newLine);
}
if (rowData.Count == 0)
{
return;
}
...@@ -149,6 +147,7 @@ public class DataSaver : MonoBehaviour ...@@ -149,6 +147,7 @@ public class DataSaver : MonoBehaviour
{ {
File.Create(filePath); File.Create(filePath);
newLineAdded = false; newLineAdded = false;
stable = true;
return; return;
} }
...@@ -164,14 +163,14 @@ public class DataSaver : MonoBehaviour ...@@ -164,14 +163,14 @@ public class DataSaver : MonoBehaviour
{ {
if (!newLineAdded) if (!newLineAdded)
{ {
string newLine = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", string newLine2 = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}",
"distance x from first pivot", "distance y from first pivot", "distance z from first pivot", "distance x from first pivot", "distance y from first pivot", "distance z from first pivot",
"current speed", "last pivot name", "distance x to last pivot", "distance y to last pivot", "current speed", "last pivot name", "distance x to last pivot", "distance y to last pivot",
"distance z to last pivot", "distance z to last pivot",
"total distance with wall", "distance x with wall", "distance y with wall", "distance z with wall" "total distance with wall", "distance x with wall", "distance y with wall", "distance z with wall"
); );
csv = new StringBuilder(); csv = new StringBuilder();
csv.AppendLine(newLine); csv.AppendLine(newLine2);
newLineAdded = true; newLineAdded = true;
} }
File.AppendAllText(filePath, csv.ToString()); File.AppendAllText(filePath, csv.ToString());
...@@ -181,8 +180,17 @@ public class DataSaver : MonoBehaviour ...@@ -181,8 +180,17 @@ public class DataSaver : MonoBehaviour
{ {
newLineAdded = false; newLineAdded = false;
Console.WriteLine(e); Console.WriteLine(e);
stable = true;
} }
stable = true;
});
} }
// Following method is used to retrive the relative path as device platform // Following method is used to retrive the relative path as device platform
private string getPath() private string getPath()
......
using System.Collections; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor;
using UnityEngine; using UnityEngine;
[Serializable]
[RequireComponent(typeof(MeshCollider))] [RequireComponent(typeof(MeshCollider))]
public class Wall : MonoBehaviour public class Wall : MonoBehaviour
{ {
// Start is called before the first frame update // Start is called before the first frame update
private MeshCollider coll; private MeshCollider coll;
private Vector3 lastPos = Vector3.zero;
private Vector3 lastPoint = Vector3.zero;
void Start() void Start()
{ {
coll = this.GetComponent<MeshCollider>(); coll = this.GetComponent<MeshCollider>();
...@@ -26,13 +35,25 @@ public class Wall : MonoBehaviour ...@@ -26,13 +35,25 @@ public class Wall : MonoBehaviour
} }
public Vector3 newMethod(Vector3 point)
public void newMethod(Vector3 point,Action<Vector3,float> onComplete)
{ {
StartCoroutine(findVertex(point, onComplete));
}
private IEnumerator findVertex(Vector3 point,Action<Vector3,float> onComplete)
{
Debug.Log("wtf");
point = transform.InverseTransformPoint(point); point = transform.InverseTransformPoint(point);
Mesh mesh = GetComponent<MeshFilter>().mesh; Mesh mesh = GetComponent<MeshFilter>().mesh;
float minDistanceSqr = Mathf.Infinity; float minDistanceSqr = Mathf.Infinity;
Vector3 nearestVertex = Vector3.zero; Vector3 nearestVertex = Vector3.zero;
int check = 0;
// scan all vertices to find nearest // scan all vertices to find nearest
foreach (Vector3 vertex in mesh.vertices) foreach (Vector3 vertex in mesh.vertices)
{ {
...@@ -43,13 +64,32 @@ public class Wall : MonoBehaviour ...@@ -43,13 +64,32 @@ public class Wall : MonoBehaviour
minDistanceSqr = distSqr; minDistanceSqr = distSqr;
nearestVertex = vertex; nearestVertex = vertex;
} }
check++;
if (check == 500)
{
yield return null;
check = 0;
}
} }
// convert nearest vertex back to world space // convert nearest vertex back to world space
Debug.Log("--> "+ point +" " +minDistanceSqr + " " + transform.TransformPoint(nearestVertex)); Debug.Log("--> "+ point +" " +minDistanceSqr + " " + transform.TransformPoint(nearestVertex));
return transform.TransformPoint(nearestVertex);
onComplete(transform.TransformPoint(nearestVertex), minDistanceSqr);
lastPos = transform.TransformPoint(nearestVertex);
lastPoint = transform.TransformPoint(point);
Debug.Log(lastPoint);
yield break;
} }
public void OnDrawGizmos()
{
Gizmos.color = Color.yellow;
Gizmos.DrawLine(lastPoint,lastPos);
Gizmos.DrawWireSphere(lastPos, 1.5f);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment