0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rigidbody2Dの移動・回転の制限をC#から行う

Posted at

Rigidbody2Dの移動・回転の制限

移動・回転の制限をするオブジェクトにRigidbody2dがついているか確認してください。
Rigidbodyconstraints2D(Unity公式のやつ)
X軸の移動を制限したい場合は

gameobjcet.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX
でできます。(gameobjcetには移動回転の制限をさせたいオブジェクトがはいります)

移動と回転の制限

X軸の移動を制限しつつ回転も制限したいと思うこともあると思います。
Rigidbody2D.constraints

ビットや演算子を用いて複数の制限を組み合わせることができます。

ここを踏まえてX軸の移動と回転の制限を行うコードは

gameobject.GetComponent().constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation

となります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?