Skip to content

Instantly share code, notes, and snippets.

@matsuyoro
Last active April 11, 2016 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsuyoro/49f47e1c877a2092c28f to your computer and use it in GitHub Desktop.
Save matsuyoro/49f47e1c877a2092c28f to your computer and use it in GitHub Desktop.
Unity rigidbody2Dでよく使うメソッド一覧 ref: http://qiita.com/matsuyoro/items/e32b4fd12d20e5c06614
transform.localEulerAngles.z;
GetComponent<Rigidbody2D> ().velocity.y; // 上下
GetComponent<Rigidbody2D> ().velocity.x; // 左右
Vector2 v;
v.x = Mathf.Cos(Mathf.Deg2Rad * direction) * speed;
v.y = Mathf.Sin(Mathf.Deg2Rad * direction) * speed;
GetComponent<Rigidbody2D>().velocity = v;
GetComponent<Rigidbody2D> ().velocity.magnitude
dirVelocity = Mathf.Atan2 (GetComponent<Rigidbody2D>().velocity.y, GetComponent<Rigidbody2D>().velocity.x) * Mathf.Rad2Deg;
GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.FreezeRotation; // 回転させないように、zだけ固定
GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.FreezePosition; // x,y,z 全て固定
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