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.

Vector3操作スクリプト(ランダム方向、要素の最大値を取得)

Posted at

非常に簡単な計算なのでその都度コードを組めばいいだけなんですが、けっこう頻度が高いのでStaticスクリプトにしてます。

Vector3でランダムな方向を取得するRandomVector3()
Vector3のxyz要素のうち最大の絶対値を持つ要素を取り出すMaxElementOfVector3(Vector3 v)

C#Calc.cs
    public static Vector3 RandomVector3()
    {
        Vector3 v = Vector3.zero;
        v.x = Random.Range(-1.0f, 1.0f);
        v.y = Random.Range(-1.0f, 1.0f);
        v.z = Random.Range(-1.0f, 1.0f);
        return v;
    }
    public static float MaxElementOfVector3(Vector3 v)
    {
        float[] element_value = new float[] { Mathf.Abs(v.x), Mathf.Abs(v.y), Mathf.Abs(v.z) };
        return Mathf.Max(element_value);
    }
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?