使用 velocity/angularvelocity 获取游戏对象以复制目标位置和旋转

Get a gameobject to copy a target position and rotation with velocity/angularvelocity

我有一个 gameobject,我需要通过仅更改 velocityangularvelocity 来跟随另一个 gameobject(具有相同的方向和位置)。 对于职位来说很简单:

    clone.velocity = (target.transform.position - clone.transform.position) * k;

但是对于 angularvelocity 我没有找到,看来我需要将 Quaternion.FromToRotation 与类似的东西一起使用 :

    Vector3 oldpoint = clone.transform.TransformDirection(Vector3.up);
    Vector3 newpoint = target.transform.TransformDirection(Vector3.up);
    var av=Quaternion.FromToRotation(oldpoint,newpoint);

但它 returns 是 quaternionangularvelocityvector3,我找不到如何转换它。

使用Quaternion.ToAngleAxis:

Vector3 oldpoint = clone.transform.TransformDirection(Vector3.up);
Vector3 newpoint = target.transform.TransformDirection(Vector3.up);
Quaternion av = Quaternion.FromToRotation(oldpoint,newpoint);

float angle;
Vector3 axis;

av.ToAngleAxis(out angle, out axis);

// Convert to signed angle
angle = Mathf.Repeat(angle + 180f, 360f) - 180f;

// depending on how rapidly you want it to rotate to match it 
// don't set too high or it might overshoot
float angularVelocityFactor = 0.01f; 

clone.angularVelocity = (angularVelocityFactor * angle) * axis;