Last active
April 30, 2021 05:13
-
-
Save daichi-takezawa/eceb3eca90d024ce308dfcbc8883a7ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector3 latestPos; | |
public void FixedUpdate() | |
{ | |
//前フレームとの位置の差から進行方向を割り出してその方向に回転します。 | |
Vector3 differenceDis = new Vector3(transform.position.x, 0, transform.position.z) - new Vector3(latestPos.x, 0, latestPos.z); | |
latestPos = transform.position; | |
if (Mathf.Abs(differenceDis.x) > 0.001f || Mathf.Abs(differenceDis.z) > 0.001f) | |
{ | |
if (movingDirecion == new Vector3(0, 0, 0)) return; | |
Quaternion rot = Quaternion.LookRotation(differenceDis); | |
rot = Quaternion.Slerp(rb.transform.rotation, rot, 0.2f); | |
this.transform.rotation = rot; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment