简体   繁体   English

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

[英]unity: rope swing 3d character jump on start

I try to create a rope-swinging (penudulum like, around virtual point) mechanic in unity. 我尝试统一创建一个绳索摆动(围绕虚拟点的摆锤)机械师。 But on first frame of swing my character suddenly jump far back and down and only then continue moving forward and down pendulum like. 但是在挥杆的第一帧,我的角色突然跳来回去,然后像钟摆一样继续向前和向下移动。

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;

Could it be due to Time.deltaTime being 0 on the first frame? 可能是因为第一帧中的Time.deltaTime为0吗? Therefore the line jMotor.moveDirection *Time.deltaTime would return 0 and testPos would equal transform.position + 0 因此, jMotor.moveDirection *Time.deltaTime行将返回0,而testPos将等于transform.position + 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM