1
1
using UnityEngine ;
2
- using System . Collections ;
3
- using UnityEngine . Experimental . GlobalIllumination ;
4
2
5
3
// A very simplistic car driving on the x-z plane.
6
4
@@ -27,16 +25,27 @@ void Update()
27
25
rotation *= Time . deltaTime ;
28
26
29
27
// Move translation along the object's z-axis
30
- transform . Translate ( 0 , translation , 0 ) ;
28
+ Translate ( transform , new Vector3 ( 0 , translation , 0 ) ) ;
31
29
32
30
// Rotate around our y-axis
33
31
transform . Rotate ( 0 , 0 , - rotation ) ;
34
32
}
35
33
36
-
37
- public void RotateTankTo ( float desiredAngle )
34
+ void Translate ( Transform transform , Vector3 dir )
38
35
{
39
- float radAngle = ( desiredAngle * Mathf . PI ) / 180 ;
40
- transform . up = UMath . RotateVector ( transform . up , radAngle , false ) ;
36
+ float angleYAxis = UMath . Angle ( Vector3 . up , transform . up ) ;
37
+
38
+ if ( UMath . IsDirectionClockWise ( Vector3 . up , transform . up ) )
39
+ {
40
+ angleYAxis = 2 * Mathf . PI - angleYAxis ;
41
+ }
42
+
43
+ float velX = - dir . y * Mathf . Sin ( angleYAxis ) ;
44
+ float velY = dir . y * Mathf . Cos ( angleYAxis ) ;
45
+
46
+
47
+ transform . position += new Vector3 ( velX , velY , 0 ) ;
41
48
}
49
+
50
+
42
51
}
0 commit comments