Last active
April 11, 2016 23:58
-
-
Save matsuyoro/49f47e1c877a2092c28f to your computer and use it in GitHub Desktop.
Unity rigidbody2Dでよく使うメソッド一覧 ref: http://qiita.com/matsuyoro/items/e32b4fd12d20e5c06614
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
transform.localEulerAngles.z; |
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
GetComponent<Rigidbody2D> ().velocity.y; // 上下 | |
GetComponent<Rigidbody2D> ().velocity.x; // 左右 |
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
Vector2 v; | |
v.x = Mathf.Cos(Mathf.Deg2Rad * direction) * speed; | |
v.y = Mathf.Sin(Mathf.Deg2Rad * direction) * speed; | |
GetComponent<Rigidbody2D>().velocity = v; |
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
GetComponent<Rigidbody2D> ().velocity.magnitude |
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
dirVelocity = Mathf.Atan2 (GetComponent<Rigidbody2D>().velocity.y, GetComponent<Rigidbody2D>().velocity.x) * Mathf.Rad2Deg; |
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
GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.FreezeRotation; // 回転させないように、zだけ固定 | |
GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.FreezePosition; // x,y,z 全て固定 |
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
GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.None; // x,y,zの固定解除 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment