Skip to content

Commit 3ba6bc7

Browse files
committed
creating my own Translate method
1 parent 13c6a9d commit 3ba6bc7

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Assets/Scripts/Drive.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using UnityEngine;
2-
using System.Collections;
3-
using UnityEngine.Experimental.GlobalIllumination;
42

53
// A very simplistic car driving on the x-z plane.
64

@@ -27,16 +25,27 @@ void Update()
2725
rotation *= Time.deltaTime;
2826

2927
// Move translation along the object's z-axis
30-
transform.Translate(0, translation, 0);
28+
Translate(transform, new Vector3(0, translation, 0));
3129

3230
// Rotate around our y-axis
3331
transform.Rotate(0, 0, -rotation);
3432
}
3533

36-
37-
public void RotateTankTo(float desiredAngle)
34+
void Translate(Transform transform, Vector3 dir)
3835
{
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);
4148
}
49+
50+
4251
}

0 commit comments

Comments
 (0)