Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
curvedflats
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
6
Issues
6
List
Boards
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
Flatland
curvedflats
Commits
2588e633
Commit
2588e633
authored
5 years ago
by
16이진형
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto move only one path
parent
746a831e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
209 additions
and
21 deletions
+209
-21
FlatlandMovement.cs
Assets/Scripts/FlatlandMovement.cs
+137
-4
PathRenderer.cs
Assets/Scripts/PathRenderer.cs
+28
-0
Planemovement.cs
Assets/Scripts/Planemovement.cs
+10
-6
PlayerMovement.cs
Assets/Scripts/PlayerMovement.cs
+5
-0
UIManager.cs
Assets/Scripts/UIManager.cs
+29
-11
No files found.
Assets/Scripts/FlatlandMovement.cs
View file @
2588e633
...
@@ -12,20 +12,153 @@ public class FlatlandMovement : MonoBehaviour
...
@@ -12,20 +12,153 @@ public class FlatlandMovement : MonoBehaviour
protected
int
cnt
=
0
;
protected
int
cnt
=
0
;
protected
double
beta
=
0.5f
;
// v/c
protected
double
beta
=
0.5f
;
// v/c
protected
MatrixBuilder
<
double
>
M
=
Matrix
<
double
>.
Build
;
protected
VectorBuilder
<
double
>
V
=
Vector
<
double
>.
Build
;
public
Vector3
alpha
=
new
Vector3
(
0.1f
,
0.0f
,
0.0f
);
// proper acceleration
public
Vector3
alpha
=
new
Vector3
(
0.1f
,
0.0f
,
0.0f
);
// proper acceleration
public
Vector3
v
;
public
Vector3
v
;
public
Vector3
orientation
;
public
Vector3
orientation
;
public
LevelManager
Levelm
anager
;
public
LevelManager
levelM
anager
;
public
double
gamma
=
1.0f
;
public
double
gamma
=
1.0f
;
public
double
time
=
0.0f
;
public
double
time
=
0.0f
;
// Start is called before the first frame update
public
GameObject
theobject
;
public
GameObject
theobject
;
protected
MatrixBuilder
<
double
>
M
=
Matrix
<
double
>.
Build
;
// 마우스로 이동할때 하용하는 변수들.
protected
VectorBuilder
<
double
>
V
=
Vector
<
double
>.
Build
;
bool
isAutoMove
=
false
;
Vector3
nowDest
;
/// <summary>
/// 앞으로 남은 경로들.
/// </summary>
List
<
Vector3
>
paths
=
new
List
<
Vector3
>();
/// <summary>
/// 앞으로 남은 목적지 속력
/// </summary>
List
<
float
>
pathVelocitys
=
new
List
<
float
>();
protected
void
Update
()
{
if
(
isAutoMove
)
{
Vector3
tmp
=
new
Vector3
(
transform
.
position
.
x
,
0
,
transform
.
position
.
z
);
if
(
SpaceLength
(
nowDest
,
transform
.
position
)
<
0.1f
||
SpaceInnerPorduct
(
nowDest
-
tmp
,
v
)
<
0
)
{
//목적지 근접 or 넘어가면
Debug
.
Log
(
"dest"
+
nowDest
);
Debug
.
Log
(
"position"
+
transform
.
position
);
if
(
paths
.
Count
>=
1
)
{
// 다음 목적지가 있을떄.
MoveTo
(
paths
[
0
],
pathVelocitys
[
0
]);
//이동한다.
paths
.
RemoveAt
(
0
);
pathVelocitys
.
RemoveAt
(
0
);
}
else
{
//다음목적지 없을때
v
=
Vector3
.
zero
;
nowDest
=
Vector3
.
zero
;
isAutoMove
=
false
;
}
}
}
}
/// <summary>
/// 시간축 y을 무시한
/// 거리
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
protected
float
SpaceLength
(
Vector3
a
,
Vector3
b
)
{
return
Mathf
.
Sqrt
((
a
.
x
-
b
.
x
)
*
(
a
.
x
-
b
.
x
)
+
(
a
.
z
-
b
.
z
)
*
(
a
.
z
-
b
.
z
));
}
/// <summary>
/// 시간축 y을 무시한
/// 내적
/// </summary>
/// <param name="a">xy가 공간</param>
/// <param name="b">xz가 공간</param>
/// <returns></returns>
protected
float
SpaceInnerPorduct
(
Vector3
a
,
Vector3
b
)
{
return
a
.
x
*
b
.
x
+
a
.
z
*
b
.
z
;
}
/// <summary>
/// 여러 위치를 거쳐서 이동합니다.
/// </summary>
/// <param name="path">목적지 리스트 0 번은 현재 위치 x y 가 공간</param>
/// <param name="v"> 경로별 속력 0번은 0.0f </param>
public
bool
MoveTo
(
List
<
Vector3
>
path
,
List
<
float
>
v
)
{
//Debug.Log("aa");
for
(
int
i
=
1
;
i
<
v
.
Count
;
i
++)
{
//Debug.Log(v[i]);
//속력 확인
if
(
v
[
1
]
<
0.0001f
)
{
return
false
;
}
}
if
(
path
.
Count
>=
2
)
{
paths
=
new
List
<
Vector3
>();
//xy 공간 -> xz 공간
foreach
(
var
a
in
path
)
{
paths
.
Add
(
new
Vector3
(
a
.
x
,
0
,
a
.
y
));
}
pathVelocitys
=
new
List
<
float
>(
v
);
//더미 제거
paths
.
RemoveAt
(
0
);
pathVelocitys
.
RemoveAt
(
0
);
}
MoveTo
(
paths
[
0
],
pathVelocitys
[
0
]);
paths
.
RemoveAt
(
0
);
pathVelocitys
.
RemoveAt
(
0
);
return
true
;
}
/// <summary>
/// 목적지로 바로 이동합니다.
/// </summary>
/// <param name="path">목적지 x z 가 공간</param>
/// <param name="v">속력</param>
private
bool
MoveTo
(
Vector3
path
,
float
v
)
{
Debug
.
Log
(
"bb"
);
Debug
.
Log
(
path
);
if
(
v
<
0.0001f
)
{
//v가 0일때.
return
false
;
}
//속도와 목적지 설정.
Vector3
tmp
=
path
;
Debug
.
Log
(
"move vector: "
+
tmp
);
tmp
.
y
=
0
;
this
.
v
=
tmp
.
normalized
*
v
*
(
float
)
Constants
.
c
;
Debug
.
Log
(
"v : "
+
this
.
v
);
this
.
nowDest
=
path
+
new
Vector3
(
transform
.
position
.
x
,
0
,
transform
.
position
.
z
);
isAutoMove
=
true
;
return
true
;
}
}
}
This diff is collapsed.
Click to expand it.
Assets/Scripts/PathRenderer.cs
View file @
2588e633
...
@@ -113,6 +113,34 @@ public class PathRenderer : MonoBehaviour
...
@@ -113,6 +113,34 @@ public class PathRenderer : MonoBehaviour
}
}
}
}
public
void
PathClear
()
{
_ResetPaths
();
}
/// <summary>
/// 현재 설정된 경로를 반환.
/// 0번은 내 위치
/// x y 가 공간 z 가 시간
/// </summary>
public
List
<
Vector3
>
PathPositions
{
get
{
return
square
.
pathList
;
}
}
/// <summary>
/// 현재 설정된 경로의 속력을 반환.
/// 0번은 0.0f
/// </summary>
public
List
<
float
>
PathVelocitys
{
get
{
return
square
.
pathVelocity
;
}
}
private
void
_InstantiatePathCollider
(
int
n
)
private
void
_InstantiatePathCollider
(
int
n
)
{
{
var
_pathCollider
=
Instantiate
(
PathColliderPrefab
,
transform
);
var
_pathCollider
=
Instantiate
(
PathColliderPrefab
,
transform
);
...
...
This diff is collapsed.
Click to expand it.
Assets/Scripts/Planemovement.cs
View file @
2588e633
...
@@ -22,6 +22,10 @@ public class Planemovement : FlatlandMovement
...
@@ -22,6 +22,10 @@ public class Planemovement : FlatlandMovement
}
}
// Update is called once per frame
// Update is called once per frame
void
Update
()
{
base
.
Update
();
}
// For physics calcs
// For physics calcs
void
FixedUpdate
()
void
FixedUpdate
()
...
@@ -29,7 +33,7 @@ public class Planemovement : FlatlandMovement
...
@@ -29,7 +33,7 @@ public class Planemovement : FlatlandMovement
var
prevup
=
transform
.
up
;
var
prevup
=
transform
.
up
;
var
prevfor
=
transform
.
forward
;
var
prevfor
=
transform
.
forward
;
var
prevorient
=
orientation
;
var
prevorient
=
orientation
;
transform
.
Translate
((
float
)
Constants
.
c
*
Vector3
.
up
*
Time
.
fixedDeltaTime
*
(
float
)
Levelm
anager
.
player
.
gamma
,
Space
.
World
);
// move up by 1 second
transform
.
Translate
((
float
)
Constants
.
c
*
Vector3
.
up
*
Time
.
fixedDeltaTime
*
(
float
)
levelM
anager
.
player
.
gamma
,
Space
.
World
);
// move up by 1 second
cnt
++;
cnt
++;
if
(
cnt
%
480
==
0
)
if
(
cnt
%
480
==
0
)
...
@@ -66,7 +70,7 @@ public class Planemovement : FlatlandMovement
...
@@ -66,7 +70,7 @@ public class Planemovement : FlatlandMovement
v
=
finaldeltav
;
v
=
finaldeltav
;
}
}
if
((
Levelm
anager
.
player
.
transform
.
position
-
transform
.
position
).
magnitude
<
1f
)
if
((
levelM
anager
.
player
.
transform
.
position
-
transform
.
position
).
magnitude
<
1f
)
{
{
toggle
=
true
;
toggle
=
true
;
}
}
...
@@ -82,7 +86,7 @@ public class Planemovement : FlatlandMovement
...
@@ -82,7 +86,7 @@ public class Planemovement : FlatlandMovement
if
(
grabbed
)
if
(
grabbed
)
{
{
v
=
Levelm
anager
.
player
.
v
;
v
=
levelM
anager
.
player
.
v
;
Debug
.
Log
(
"being grabbed"
);
Debug
.
Log
(
"being grabbed"
);
}
}
else
else
...
@@ -94,7 +98,7 @@ public class Planemovement : FlatlandMovement
...
@@ -94,7 +98,7 @@ public class Planemovement : FlatlandMovement
gamma
=
Constants
.
Gamma
(
v
.
magnitude
);
gamma
=
Constants
.
Gamma
(
v
.
magnitude
);
transform
.
Translate
(
v
*
Time
.
fixedDeltaTime
*
(
float
)
Levelm
anager
.
player
.
gamma
,
Space
.
World
);
transform
.
Translate
(
v
*
Time
.
fixedDeltaTime
*
(
float
)
levelM
anager
.
player
.
gamma
,
Space
.
World
);
var
vt
=
v
+
(
float
)
Constants
.
c
*
Vector3
.
up
;
var
vt
=
v
+
(
float
)
Constants
.
c
*
Vector3
.
up
;
...
@@ -119,7 +123,7 @@ public class Planemovement : FlatlandMovement
...
@@ -119,7 +123,7 @@ public class Planemovement : FlatlandMovement
transform
.
localScale
=
new
Vector3
(
1.0f
,
1.0f
,
(
float
)
gamma
);
// scale x' axis
transform
.
localScale
=
new
Vector3
(
1.0f
,
1.0f
,
(
float
)
gamma
);
// scale x' axis
time
+=
Time
.
fixedDeltaTime
*
(
float
)(
Levelm
anager
.
player
.
gamma
/
gamma
);
time
+=
Time
.
fixedDeltaTime
*
(
float
)(
levelM
anager
.
player
.
gamma
/
gamma
);
}
}
public
void
OnCollisionStaychild
(
Collision
collision
)
public
void
OnCollisionStaychild
(
Collision
collision
)
...
@@ -135,7 +139,7 @@ public class Planemovement : FlatlandMovement
...
@@ -135,7 +139,7 @@ public class Planemovement : FlatlandMovement
Debug
.
Log
(
"hit!"
);
Debug
.
Log
(
"hit!"
);
if
(
Mathf
.
Abs
((
float
)(
otherclock
.
GetTime
()
-
time
))
<=
1.0f
)
if
(
Mathf
.
Abs
((
float
)(
otherclock
.
GetTime
()
-
time
))
<=
1.0f
)
{
{
Levelm
anager
.
winstate
=
true
;
levelM
anager
.
winstate
=
true
;
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Assets/Scripts/PlayerMovement.cs
View file @
2588e633
...
@@ -20,6 +20,11 @@ public class PlayerMovement : FlatlandMovement
...
@@ -20,6 +20,11 @@ public class PlayerMovement : FlatlandMovement
alpha
=
new
Vector3
(
0.0f
,
0.0f
,
0.0f
);
alpha
=
new
Vector3
(
0.0f
,
0.0f
,
0.0f
);
}
}
void
Update
()
{
base
.
Update
();
}
// Update is called once per frame
// Update is called once per frame
void
FixedUpdate
()
void
FixedUpdate
()
{
{
...
...
This diff is collapsed.
Click to expand it.
Assets/Scripts/UIManager.cs
View file @
2588e633
...
@@ -26,7 +26,9 @@ public class UIManager : MonoBehaviour
...
@@ -26,7 +26,9 @@ public class UIManager : MonoBehaviour
//public Text clock2time;
//public Text clock2time;
public
Text
wintext
;
public
Text
wintext
;
public
GameObject
_pathUI
;
public
GameObject
_pathUI
;
public
LevelManager
Levelmanager
;
public
LevelManager
levelManager
;
public
PathRenderer
pathRenderer
;
private
int
prevSelectPathNum
=
-
1
;
private
int
prevSelectPathNum
=
-
1
;
private
Text
pathName
;
private
Text
pathName
;
...
@@ -54,10 +56,10 @@ public class UIManager : MonoBehaviour
...
@@ -54,10 +56,10 @@ public class UIManager : MonoBehaviour
// Update is called once per frame
// Update is called once per frame
void
Update
()
void
Update
()
{
{
mytime
.
text
=
Levelm
anager
.
player
.
time
.
ToString
()
+
" s"
;
mytime
.
text
=
levelM
anager
.
player
.
time
.
ToString
()
+
" s"
;
//clock1time.text = clock1.GetTime().ToString() + " s";
//clock1time.text = clock1.GetTime().ToString() + " s";
//clock2time.text = clock2.GetTime().ToString() + " s";
//clock2time.text = clock2.GetTime().ToString() + " s";
if
(
Levelm
anager
.
winstate
)
if
(
levelM
anager
.
winstate
)
{
{
wintext
.
gameObject
.
SetActive
(
true
);
wintext
.
gameObject
.
SetActive
(
true
);
}
}
...
@@ -142,42 +144,44 @@ public class UIManager : MonoBehaviour
...
@@ -142,42 +144,44 @@ public class UIManager : MonoBehaviour
sliderflag
=
0
;
sliderflag
=
0
;
}
}
//player movement
if
(
Input
.
GetKeyDown
(
"w"
))
if
(
Input
.
GetKeyDown
(
"w"
))
{
{
var
tmp
=
accelslider
.
GetLogScaleValue
();
var
tmp
=
accelslider
.
GetLogScaleValue
();
Levelm
anager
.
player
.
alpha
+=
new
Vector3
(
0
,
0
,
tmp
);
levelM
anager
.
player
.
alpha
+=
new
Vector3
(
0
,
0
,
tmp
);
}
}
else
if
(
Input
.
GetKeyDown
(
"a"
))
else
if
(
Input
.
GetKeyDown
(
"a"
))
{
{
var
tmp
=
accelslider
.
GetLogScaleValue
();
var
tmp
=
accelslider
.
GetLogScaleValue
();
Levelm
anager
.
player
.
alpha
+=
new
Vector3
(-
tmp
,
0
,
0
);
levelM
anager
.
player
.
alpha
+=
new
Vector3
(-
tmp
,
0
,
0
);
}
}
else
if
(
Input
.
GetKeyDown
(
"s"
))
else
if
(
Input
.
GetKeyDown
(
"s"
))
{
{
var
tmp
=
accelslider
.
GetLogScaleValue
();
var
tmp
=
accelslider
.
GetLogScaleValue
();
Levelm
anager
.
player
.
alpha
+=
new
Vector3
(
0
,
0
,
-
tmp
);
levelM
anager
.
player
.
alpha
+=
new
Vector3
(
0
,
0
,
-
tmp
);
}
}
else
if
(
Input
.
GetKeyDown
(
"d"
))
else
if
(
Input
.
GetKeyDown
(
"d"
))
{
{
var
tmp
=
accelslider
.
GetLogScaleValue
();
var
tmp
=
accelslider
.
GetLogScaleValue
();
Levelm
anager
.
player
.
alpha
+=
new
Vector3
(
tmp
,
0
,
0
);
levelM
anager
.
player
.
alpha
+=
new
Vector3
(
tmp
,
0
,
0
);
}
}
if
(
Input
.
GetKeyUp
(
"w"
))
if
(
Input
.
GetKeyUp
(
"w"
))
{
{
Levelmanager
.
player
.
alpha
-=
new
Vector3
(
0
,
0
,
Levelm
anager
.
player
.
alpha
.
z
);
levelManager
.
player
.
alpha
-=
new
Vector3
(
0
,
0
,
levelM
anager
.
player
.
alpha
.
z
);
}
}
else
if
(
Input
.
GetKeyUp
(
"a"
))
else
if
(
Input
.
GetKeyUp
(
"a"
))
{
{
Levelmanager
.
player
.
alpha
-=
new
Vector3
(
Levelm
anager
.
player
.
alpha
.
x
,
0
,
0
);
levelManager
.
player
.
alpha
-=
new
Vector3
(
levelM
anager
.
player
.
alpha
.
x
,
0
,
0
);
}
}
else
if
(
Input
.
GetKeyUp
(
"s"
))
else
if
(
Input
.
GetKeyUp
(
"s"
))
{
{
Levelmanager
.
player
.
alpha
-=
new
Vector3
(
0
,
0
,
Levelm
anager
.
player
.
alpha
.
z
);
levelManager
.
player
.
alpha
-=
new
Vector3
(
0
,
0
,
levelM
anager
.
player
.
alpha
.
z
);
}
}
else
if
(
Input
.
GetKeyUp
(
"d"
))
else
if
(
Input
.
GetKeyUp
(
"d"
))
{
{
Levelmanager
.
player
.
alpha
-=
new
Vector3
(
Levelm
anager
.
player
.
alpha
.
x
,
0
,
0
);
levelManager
.
player
.
alpha
-=
new
Vector3
(
levelM
anager
.
player
.
alpha
.
x
,
0
,
0
);
}
}
}
}
...
@@ -204,4 +208,18 @@ public class UIManager : MonoBehaviour
...
@@ -204,4 +208,18 @@ public class UIManager : MonoBehaviour
velocityslider
.
UpdateValuebyVelocity
(
square
.
GetPathVelocity
(
pathNum
));
velocityslider
.
UpdateValuebyVelocity
(
square
.
GetPathVelocity
(
pathNum
));
}
}
/// <summary>
/// 현재 지정된 path를 시작합니다.
/// </summary>
public
void
PathStart
()
{
bool
result
;
result
=
levelManager
.
player
.
MoveTo
(
pathRenderer
.
PathPositions
,
pathRenderer
.
PathVelocitys
);
if
(
result
)
{
pathRenderer
.
PathClear
();
}
}
}
}
This diff is collapsed.
Click to expand it.
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