1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

UnityのVectorの==はapproximately equal

Posted at

普通、浮動小数点数の比較には==は使わない、というか使い物にならないはずなんですけど、Unityでは

if (destPosition == transform.position)
{
    // Stop Move
}

なぜかこれ、成立しちゃうんですよね
で、調べてみたら

原文

Returns true if two vectors are approximately equal.
To allow for floating point inaccuracies, the two vectors are considered equal if the magnitude of their difference is less than 1e-5.

意訳

二つのVectorが”おおよそ等しかったら”trueを返します
具体的にはVector間の距離が1e-5(10の-5乗:0.00001)より小さかったら”等しい”と判断します

ということらしいです
自前でMathf.Approximately()で比較しなくていいので楽ですね

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?