Version: 2022.3
言語: 日本語
public static float Dot (Vector3 lhs, Vector3 rhs);

説明

2 つのベクトルの内積

The dot product is a float value equal to the magnitudes of the two vectors multiplied together and then multiplied by the cosine of the angle between them.

For normalized vectors Dot returns 1 if they point in exactly the same direction, -1 if they point in completely opposite directions and zero if the vectors are perpendicular.

// detects if other transform is behind this object

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!"); } } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961