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 3 years have passed since last update.

SphereColliderのGizmoを自力で描画する

Last updated at Posted at 2020-01-30

SphereColliderのCenter、Radusは、アタッチしたTransformや親Transformの影響を受け、RadiusはScaleのx、y、zの中の最大値がzを受けるようです。

これをGizmoで描画する場合、以下のようなコードになります。


[SerializeField] private SphereCollider _sphereCollider;

private void OnDrawGizmos()
{
    Gizmos.color = Color.yellow;

    var scale = Mathf.Max(transform.lossyScale.x, transform.lossyScale.y, transform.lossyScale.z);

    var center = transform.TransformPoint(_sphereCollider.center);
    var radius = _sphereCollider.radius * scale;

    Gizmos.DrawWireSphere(center, radius);
}

collider_gizmo.gif

緑の線が、UnityEditorが描画したコライダーで、黄色の線が、自分で描画したコライダーです。一致していますね!

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?