Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Vector3.Dot

マニュアルに切り替える
public static float Dot(Vector3 lhs, Vector3 rhs);

パラメーター

説明

2 つのベクトルの内積

内積は 2 つのベクトルを乗算し、 2 つのベクトル間の角度の余弦を乗算したベクトルの大きさと同じ float 値です。

2 つのベクトルがまったく同じ方向を指している場合、正規化されたベクトルの内積は 1 を返します。 反対方向を向く場合は-1 を返します。またベクトルが垂直である場合 0 を返します。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform other; void Update() { if (other) { Vector3 forward = transform.TransformDirection(Vector3.forward); Vector3 toOther = other.position - transform.position; if (Vector3.Dot(forward, toOther) < 0) print("The other transform is behind me!"); } } }