Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
car-sim-remaster
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9631059
car-sim-remaster
Commits
098c4aaa
Commit
098c4aaa
authored
Jun 26, 2020
by
Danial KordModanlou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wall distance updated
parent
5d6c968e
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
529 additions
and
168 deletions
+529
-168
workspace.xml
.idea/.idea.car-sim-remaster/.idea/workspace.xml
+131
-134
p1.csv
Assets/CSV/p1.csv
+316
-0
DataSaver.cs
Assets/scripts/DataSaver.cs
+37
-29
Wall.cs
Assets/scripts/Wall.cs
+45
-5
No files found.
.idea/.idea.car-sim-remaster/.idea/workspace.xml
View file @
098c4aaa
This diff is collapsed.
Click to expand it.
Assets/CSV/p1.csv
View file @
098c4aaa
This diff is collapsed.
Click to expand it.
Assets/scripts/DataSaver.cs
View file @
098c4aaa
...
...
@@ -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
;
//timePassed += Time.deltaTime;
// if (timePassed > 0.1)
// {
Save
();
// }
}
...
...
@@ -83,8 +84,8 @@ public class DataSaver : MonoBehaviour
return
;
}
stable
=
false
;
List
<
string
[
]>
rowData
=
new
List
<
string
[
]>
();
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
);
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
newLine
2
=
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
(
newLine
2
);
newLineAdded
=
true
;
}
File
.
AppendAllText
(
filePath
,
csv
.
ToString
());
...
...
@@ -181,9 +180,18 @@ 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
()
{
...
...
Assets/scripts/Wall.cs
View file @
098c4aaa
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
()
{
...
...
@@ -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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment