@@ -21,11 +21,11 @@ public class Wanderer : MonoBehaviour {
21
21
public bool justEntered = false ;
22
22
23
23
// MOVEMENT
24
- private const float Velocity = 1.0f ;
25
24
private float lerpDuration = 1.5f ; // You can adjust the duration to control the speed of movement
26
25
private float lerpDurationRoom = 10.0f ;
27
26
private float lerpStartTime ;
28
27
28
+ // yum BEZIER STUFF
29
29
private List < Vector2 > controlPoints ;
30
30
private float movementDuration ;
31
31
@@ -40,28 +40,27 @@ public void Initialize(Graph navGraph, EdgeInfo start, EdgeInfo end, PathFinder
40
40
}
41
41
42
42
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 ) {
46
47
currEdge = path . Pop ( ) ;
47
48
StartCoroutine ( MoveToTarget ( currEdge . Curve ) ) ;
48
49
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 ) ) ;
59
58
}
60
- else if ( path . Count == 0 ) {
59
+
60
+ }
61
+ else if ( path . Count == 0 ) {
61
62
endEdge = navGraph . GetRandomEdge ( ) ;
62
63
path = pathFinder . FindPath ( currEdge , endEdge ) ;
63
- }
64
-
65
64
}
66
65
}
67
66
@@ -90,75 +89,53 @@ private IEnumerator MoveToTarget(ICurve curve)
90
89
}
91
90
private IEnumerator EnterRoom ( EdgeInfo edge )
92
91
{
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 ) ;
103
95
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
+ }
114
101
115
102
//changed post exit code
116
103
var exit = path . Pop ( ) ;
117
- // randomPoints.Add(exit.Curve.Point(0));
104
+ randomPoints . Add ( exit . Curve . Point ( 0 ) ) ;
118
105
path = pathFinder . FindPath ( exit , navGraph . GetRandomEdge ( ) ) ;
119
-
120
106
lerpStartTime = Time . time ;
121
107
Vector2 startPosition = this . Position ;
122
-
123
108
while ( Time . time - lerpStartTime < lerpDurationRoom )
124
109
{
125
110
float t = ( Time . time - lerpStartTime ) / lerpDuration ;
126
- // Vector2 bezierPosition = DeCasteljauRecursive(randomPoints, t);
127
- // MoveTo(bezierPosition);
111
+ Vector2 bezierPosition = DeCasteljauRecursive ( randomPoints , t ) ;
112
+ MoveTo ( bezierPosition ) ;
128
113
yield return null ;
129
114
}
130
-
115
+
131
116
justEntered = true ;
132
117
isInRoom = false ;
133
118
yield return null ;
119
+
134
120
}
135
121
136
- private Vector2 DeCasteljauRecursive ( List < Vector2 > points , float t )
122
+ private Vector2 DeCasteljauRecursive ( List < Vector2 > points , float t )
123
+ {
124
+ if ( points . Count == 1 )
137
125
{
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 ] ;
151
127
}
152
128
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
+ }
153
135
154
-
155
-
136
+ return DeCasteljauRecursive ( newPoints , t ) ;
137
+ }
156
138
}
157
-
158
-
159
-
160
-
161
-
162
139
}
163
140
164
141
0 commit comments