团结:绳索秋千3d角色开始跳

时间:2019-02-13 10:40:43

标签: c# swing unity3d

我尝试统一创建一个绳索摆动(像虚拟点一样的摆锤)机械师。但是在挥杆的第一帧,我的角色突然跳来跳去,然后又像钟摆一样继续向前和向下移动。

void InitSwing(){
    lineLenght = (transform.position - virtualLinePoint).sqrMagnitude;}

    public void SwingLocomotion()
    {
        Vector3 testPos = transform.position + jMotor.moveDirection *Time.deltaTime;
        float newLenght = (testPos - virtualLinePoint).sqrMagnitude;
        if (newLenght != lineLenght)
        {
            testPos = virtualLinePoint + (testPos - virtualLinePoint).normalized * lineLenght;

        }
        transform.position = testPos;

1 个答案:

答案 0 :(得分:0)

是否可能是由于第一帧中的Time.deltaTime为0?因此,行jMotor.moveDirection *Time.deltaTime将返回0,而testPos将等于transform.position + 0