Skip to content

Commit 05e8022

Browse files
committed
Wrinkle smoothing
1 parent 1d8dd77 commit 05e8022

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Assets/_Project/Scripts/Movement/MovePositionWanderComplex.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,21 @@ void RotateTowardsTarget2D ()
7676
//transform.right = wayPoint - transform.position;
7777

7878
// change look direction slowly
79-
transform.right = Vector3.Lerp (transform.right, (wayPoint - transform.position), rotateTimeElapsed / rotateDuration);
79+
Vector3 temp = Vector3.Lerp(transform.right, (wayPoint - transform.position), rotateTimeElapsed / rotateDuration);
80+
81+
// Values used to check for bad flipping
82+
float safetyX = Mathf.Abs(-1f - Mathf.Round(temp.x * 100.0f) / 100.0f);
83+
float safetyY = Mathf.Round(temp.y * 100.0f) / 100.0f;
84+
85+
// If new rotation would flip player in y rotation, prevent this
86+
if (safetyX <= 0.1f && safetyY == 0)
87+
{
88+
temp = new Vector3(-0.9f, 0.1f, 0);
89+
}
90+
91+
// Set right vector
92+
transform.right = temp;
93+
8094
rotateTimeElapsed += Time.deltaTime;
8195
}
8296

0 commit comments

Comments
 (0)