Unity5(2D)でBouncinessを設定しているのに、跳ね返らない時がある

unity5_bounce

跳返したいボールがありそれのcolliderに、

  • Friction 0
  • Bounciness 1

unity5_bounce

で設定しても跳ね返らない事があり、
なんでだろうとしらべたところ。

物理挙動の環境設定の項目の
Edit > Project Setting > Physics2Dの項目の

Velocity Threshold のデフォルトの閾値が1のため、
小さすぎる速度の場合に跳ね返らないようになっていました。

unity5_bounce2
unity5_bounce

で、Velocity Thresholdを0.1等にすると解決!

ググっても情報がなかったので、下記マニュアルが大変参考になりました。!

参考

https://docs.unity3d.com/Manual/class-Physics2DManager.html

Unityのバージョンや、Physics2D や3D用のPhysicsでは項目名が違うのでご注意!

Unity5 rigidbody2Dで、x,y,zの軸を固定する

x,y,zのいずれも固定する場合。

GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.FreezeAll;

固定を解除する場合。

GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.None;

z軸(回転)以外だけ解除する場合。

GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.FreezeRotation;

スクリーンショット 2016-04-24 22.11.20

条件式で、どのタイプで固定されているか判別する場合

if( GetComponent<Rigidbody2D> ().constraints == RigidbodyConstraints2D.FreezeAll){
  // すべて固定されていたら
}

Unity5(C#) 2Dで物理ゲーム使う際によく使うメソッド一覧


回転角度取得

transform.localEulerAngles.z

左右方向への速度

GetComponent<Rigidbody2D> ().velocity.x

上下方向への速度

GetComponent<Rigidbody2D> ().velocity.y

全方向への速度を取得

GetComponent<Rigidbody2D> ().velocity.magnitude

重力や速度が早すぎてものを貫通する時等の制御に。

指定角度への力を加える

void Boost(float,direction,float speed){
    Vector2 v;
    v.x = Mathf.Cos(Mathf.Deg2Rad * direction) * speed;
    v.y = Mathf.Sin(Mathf.Deg2Rad * direction) * speed;
    GetComponent<Rigidbody2D> ().AddForce (v); //力加算
}