当前位置:网站首页>The moveposition function of rigidbody2d of unity2d solves the problem of people or screen jitter when moving

The moveposition function of rigidbody2d of unity2d solves the problem of people or screen jitter when moving

2022-07-07 18:55:00 Cingke is true

This is a 2d Rigid body movement function

public void controlHero()
    {
    
        if ((ETCInput.GetAxis("Vertical") != 0) || (ETCInput.GetAxis("Horizontal") != 0)){
    
            rigidbody2D.MovePosition(rigidbody2D.position+Time.fixedDeltaTime*new Vector2(ETCInput.GetAxis("Horizontal"),ETCInput.GetAxis("Vertical")) * speed );
        }
        // as everyone knows , When the character moves, multiply by Time.fixedDeltaTime, Equivalent to logic in FixedUpade Call in , Every interval 0.02s Move once ;
    }

I started with FixedUpdate() Call in , As a result, the character shook unexpectedly , It has been changed many times , Think it's not smooth enough to move , Only later did I know , Consider the following rendering of the camera , Generally, the camera follows LateUpdate in , And I used cinemachine Also in LateUpdate in , Decisively changed to in LateUpdate Call the mobile function in , No shaking .

 private void LateUpdate()
    {
    
        controlHero();
    }
}

Okay, put it on Update It's fine too

原网站

版权声明
本文为[Cingke is true]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071651005916.html