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
//delegates
public static Func<Vector3, Vector3> sideDistance;
public static Action<Vector3,Action<Vector3,float>> sideDistance;
// Start is called before the first frame update
......@@ -61,11 +61,12 @@ public class DataSaver : MonoBehaviour
pName = menu.PlayerName;
timePassed += Time.deltaTime;
Save();
//timePassed += Time.deltaTime;
// if (timePassed > 0.1)
// {
Save();
// }
}
......@@ -83,8 +84,8 @@ public class DataSaver : MonoBehaviour
return;
}
List<string[]> rowData = new List<string[]>();
stable = false;
var csv = new StringBuilder();
if (!pName.Equals(curentName))
{
......@@ -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.
if (timePassed > 0.1)
{
string[] rowDataTemp = new string[12];
rowDataTemp[0] = "" + (myPlayer.transform.position.x - firstPos.x);// distance to first pivot
rowDataTemp[1] = "" + (myPlayer.transform.position.y - firstPos.y);
rowDataTemp[2] = "" + (myPlayer.transform.position.z - firstPos.z);
string[] rowDataTemp = new string[12];
rowDataTemp[0] = "" + (playerPos.x - firstPos.x);// distance to first pivot
rowDataTemp[1] = "" + (playerPos.y - firstPos.y);
rowDataTemp[2] = "" + (playerPos.z - firstPos.z);
rowDataTemp[3] = ""+ myPlayer.speed; //current speed
rowDataTemp[4] = "" + pivotName; // last pivot name
rowDataTemp[5] = "" + (myPlayer.transform.position.x - pivotPos.x);// local distance to last pivot
rowDataTemp[6] = "" + (myPlayer.transform.position.y - pivotPos.y);
rowDataTemp[7] = ""+(myPlayer.transform.position.z - pivotPos.z);
rowDataTemp[5] = "" + (playerPos.x - pivotPos.x);// local distance to last pivot
rowDataTemp[6] = "" + (playerPos.y - pivotPos.y);
rowDataTemp[7] = ""+(playerPos.z - pivotPos.z);
if (sideDistance != null)
{
Vector3 hitPoint = sideDistance(myPlayer.transform.position);
rowDataTemp[8] = "" + Vector3.Distance(myPlayer.transform.position, hitPoint);
rowDataTemp[9] = "" + hitPoint.x;
rowDataTemp[10] = "" + hitPoint.y;
rowDataTemp[11] = "" + hitPoint.z;
//distanceComponent hitPoint = sideDistance(myPlayer.transform.position);
rowDataTemp[8] = "" + distanceFloat;
rowDataTemp[9] = "" + wallPos.x;
rowDataTemp[10] = "" + wallPos.y;
rowDataTemp[11] = "" + wallPos.z;
}
else
{
......@@ -127,18 +130,13 @@ public class DataSaver : MonoBehaviour
rowDataTemp[10] = "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],
rowDataTemp[5], rowDataTemp[6], rowDataTemp[7], rowDataTemp[8], rowDataTemp[9], rowDataTemp[10], rowDataTemp[11]);
timePassed = 0;
csv.AppendLine(newLine);
}
if (rowData.Count == 0)
{
return;
}
......@@ -149,6 +147,7 @@ public class DataSaver : MonoBehaviour
{
File.Create(filePath);
newLineAdded = false;
stable = true;
return;
}
......@@ -164,14 +163,14 @@ public class DataSaver : MonoBehaviour
{
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",
"current speed", "last pivot name", "distance x to last pivot", "distance y to last pivot",
"distance z to last pivot",
"total distance with wall", "distance x with wall", "distance y with wall", "distance z with wall"
);
csv = new StringBuilder();
csv.AppendLine(newLine);
csv.AppendLine(newLine2);
newLineAdded = true;
}
File.AppendAllText(filePath, csv.ToString());
......@@ -181,8 +180,17 @@ public class DataSaver : MonoBehaviour
{
newLineAdded = false;
Console.WriteLine(e);
stable = true;
}
stable = true;
});
}
// Following method is used to retrive the relative path as device platform
private string getPath()
......
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[Serializable]
[RequireComponent(typeof(MeshCollider))]
public class Wall : MonoBehaviour
{
// Start is called before the first frame update
private MeshCollider coll;
private Vector3 lastPos = Vector3.zero;
private Vector3 lastPoint = Vector3.zero;
void Start()
{
coll = this.GetComponent<MeshCollider>();
......@@ -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);
Mesh mesh = GetComponent<MeshFilter>().mesh;
float minDistanceSqr = Mathf.Infinity;
Vector3 nearestVertex = Vector3.zero;
int check = 0;
// scan all vertices to find nearest
foreach (Vector3 vertex in mesh.vertices)
{
......@@ -43,13 +64,32 @@ public class Wall : MonoBehaviour
minDistanceSqr = distSqr;
nearestVertex = vertex;
}
check++;
if (check == 500)
{
yield return null;
check = 0;
}
}
// convert nearest vertex back to world space
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