Skip to content

Commit 592048f

Browse files
committed
Reverting wanderers
1 parent 8c80095 commit 592048f

File tree

3 files changed

+44
-69
lines changed

3 files changed

+44
-69
lines changed

Assets/Scripts/MyDebug/DebugRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class DebugRenderer : MonoBehaviour
2828
/*** Move stuff ***/
2929
private float lerpDuration = 1.0f; // You can adjust the duration to control the speed of movement
3030
private float lerpStartTime;
31-
private BezierCurveMover curveMover;
3231
/*
3332
private bool justEntered = false;
3433
*/

Assets/Scripts/Navigation/Wanderer.cs

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public class Wanderer : MonoBehaviour {
2121
public bool justEntered = false;
2222

2323
// MOVEMENT
24-
private const float Velocity = 1.0f;
2524
private float lerpDuration = 1.5f; // You can adjust the duration to control the speed of movement
2625
private float lerpDurationRoom= 10.0f;
2726
private float lerpStartTime;
2827

28+
// yum BEZIER STUFF
2929
private List<Vector2> controlPoints;
3030
private float movementDuration;
3131

@@ -40,28 +40,27 @@ public void Initialize(Graph navGraph, EdgeInfo start, EdgeInfo end, PathFinder
4040
}
4141

4242

43-
void Update(){
44-
if (!isInRoom) {
45-
if (!isMoving && path.Count > 0) {
43+
void Update()
44+
{
45+
if (isInRoom) return;
46+
if (!isMoving && path.Count > 0) {
4647
currEdge = path.Pop();
4748
StartCoroutine(MoveToTarget(currEdge.Curve));
4849
if (currEdge.Tag == EdgeTag.Doorway && justEntered == false)
49-
{
50-
isInRoom = true;
51-
StartCoroutine(EnterRoom(currEdge));
52-
}
53-
else
54-
{
55-
justEntered = false;
56-
StartCoroutine(MoveToTarget(currEdge.Curve));
57-
}
58-
50+
{
51+
isInRoom = true;
52+
StartCoroutine(EnterRoom(currEdge));
53+
}
54+
else
55+
{
56+
justEntered = false;
57+
StartCoroutine(MoveToTarget(currEdge.Curve));
5958
}
60-
else if (path.Count == 0) {
59+
60+
}
61+
else if (path.Count == 0) {
6162
endEdge = navGraph.GetRandomEdge();
6263
path = pathFinder.FindPath(currEdge, endEdge);
63-
}
64-
6564
}
6665
}
6766

@@ -90,75 +89,53 @@ private IEnumerator MoveToTarget(ICurve curve)
9089
}
9190
private IEnumerator EnterRoom(EdgeInfo edge)
9291
{
93-
var vertexInfo = navGraph.GetVertex(edge.ToVertex);
94-
var controls = new Vector3[4];
95-
controls[0] = edge.Curve.Point(0);
96-
controls[1] = vertexInfo.region.RandPoint();
97-
controls[2] = vertexInfo.region.RandPoint();
98-
controls[3] = edge.Curve.Point(1);
99-
BezierCurve bezier = new BezierCurve(controls);
100-
101-
var length = bezier.Length();
102-
var timeInRoom = length / Velocity;
92+
List<Vector2> randomPoints = new List<Vector2>();
93+
randomPoints.Add(currEdge.Curve.Point(1));
94+
int points = UnityEngine.Random.Range(4, 10);
10395

104-
//
105-
// List<Vector2> randomPoints = new List<Vector2>();
106-
// randomPoints.Add(currEdge.Curve.Point(1));
107-
// int points = UnityEngine.Random.Range(4, 10);
108-
//
109-
// for (int i = 0; i < 5; i++)
110-
// {
111-
// Vector2 randomPoint = navGraph.GetVertices()[edge.ToVertex].region.RandPoint();
112-
// randomPoints.Add(randomPoint);
113-
// }
96+
for (int i = 0; i < 5; i++)
97+
{
98+
Vector2 randomPoint = navGraph.GetVertex(edge.ToVertex).region.RandPoint();
99+
randomPoints.Add(randomPoint);
100+
}
114101

115102
//changed post exit code
116103
var exit = path.Pop();
117-
//randomPoints.Add(exit.Curve.Point(0));
104+
randomPoints.Add(exit.Curve.Point(0));
118105
path = pathFinder.FindPath(exit, navGraph.GetRandomEdge());
119-
120106
lerpStartTime = Time.time;
121107
Vector2 startPosition = this.Position;
122-
123108
while (Time.time - lerpStartTime < lerpDurationRoom)
124109
{
125110
float t = (Time.time - lerpStartTime) / lerpDuration;
126-
//Vector2 bezierPosition = DeCasteljauRecursive(randomPoints, t);
127-
//MoveTo(bezierPosition);
111+
Vector2 bezierPosition = DeCasteljauRecursive(randomPoints, t);
112+
MoveTo(bezierPosition);
128113
yield return null;
129114
}
130-
115+
131116
justEntered = true;
132117
isInRoom = false;
133118
yield return null;
119+
134120
}
135121

136-
private Vector2 DeCasteljauRecursive(List<Vector2> points, float t)
122+
private Vector2 DeCasteljauRecursive(List<Vector2> points, float t)
123+
{
124+
if (points.Count == 1)
137125
{
138-
if (points.Count == 1)
139-
{
140-
return points[0];
141-
}
142-
143-
List<Vector2> newPoints = new List<Vector2>();
144-
for (int i = 0; i < points.Count - 1; i++)
145-
{
146-
Vector2 newPoint = Vector2.Lerp(points[i], points[i + 1], t);
147-
newPoints.Add(newPoint);
148-
}
149-
150-
return DeCasteljauRecursive(newPoints, t);
126+
return points[0];
151127
}
152128

129+
List<Vector2> newPoints = new List<Vector2>();
130+
for (int i = 0; i < points.Count - 1; i++)
131+
{
132+
Vector2 newPoint = Vector2.Lerp(points[i], points[i + 1], t);
133+
newPoints.Add(newPoint);
134+
}
153135

154-
155-
136+
return DeCasteljauRecursive(newPoints, t);
137+
}
156138
}
157-
158-
159-
160-
161-
162139
}
163140

164141

Assets/Scripts/Navigation/WandererManage.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class WandererManager : MonoBehaviour {
1717
private bool isInitialized = false;
1818

1919
public void Initialize(Graph graph) {
20-
navGraph = graph;
21-
isInitialized = true;
22-
}
20+
navGraph = graph;
21+
isInitialized = true;
22+
}
2323

2424
void Start() {
2525

@@ -37,7 +37,6 @@ void Start() {
3737
wanderers.Add(wander);
3838
_drawables.Add(new DebugSquare() {position = wander.Position});
3939
}
40-
4140
}
4241

4342
void Update() {

0 commit comments

Comments
 (0)