相对于另一个点的Unity翻译点

我有两点-假设A(x1,y1,z1)和B(x2,y2,z2)。我需要做的是在按下横轴的同时将这两个点都移到Vector AB的方向上。如何使用Translate方法实现这一目标?就像我需要写这样的东西:

A.translate(pointingVector,Space.World)

点B的移动会自动适应点A的变换,因此无需移动它,因为移动A点也会在不更改其长度和方向的情况下移动AB向量。

speedisk 回答:相对于另一个点的Unity翻译点

如果我正确理解了您的意思,那么只需将2个点沿着它们创建的Vector移动即可。所以首先您需要创建方向矢量:

// Gets a vector that points from the first point's position to the second's.
var (or Vector3) direction = p1.position - p2.position;

然后只要按横轴,就将那个矢量的2点位置增加:

p1.position += direction * Time.deltaTime
本文链接:https://www.f2er.com/3146359.html

大家都在问