指向被减向量
// Gets a vector that points from the player's position to the target's. var heading = target.position - player.position;
标准化向量
var distance = heading.magnitude; var direction = heading / distance; // This is now the normalized direction.
比较距离,避免求平方根
if (heading.sqrMagnitude < maxRange * maxRange) { // Target is within range. }
给三个点,计算三点所在平面的法向量
var a: Vector3; var b: Vector3; var c: Vector3; var side1: Vector3 = b - a; var side2: Vector3 = c - a; var perp: Vector3 = Vector3.Cross(side1, side2);
标准化:
var perpLength = perp.magnitude; perp /= perpLength;
此三点构成的三角形的面积为perpLength/2。
某方向上的速度。例,前进方向的分速度。方向向量必须是单位向量(标准化向量)
var fwdSpeed = Vector3.Dot(rigidbody.velocity, transform.forward);