문제

I have this basic script in my game for navigating my character around a top down level, but every time I press any of the keys, there's a slight input lag and the screen freezes for just a second.

I'm not sure how to fix it. If anyone had any ideas, I'd appreciate it.

var walkSpeed: float = 7.0;

function Start () {

}

function Update () {

    rigidbody.freezeRotation = true;

    if(Input.GetKey("w")) transform.Translate(Vector3(0, 0, 1) * Time.deltaTime * walkSpeed);
    if(Input.GetKey("s")) transform.Translate(Vector3(0, 0, -1) * Time.deltaTime * walkSpeed);
    if(Input.GetKey("a")) transform.Translate(Vector3(-1, 0, 0) * Time.deltaTime * walkSpeed);
    if(Input.GetKey("d")) transform.Translate(Vector3(1, 0, 0) * Time.deltaTime * walkSpeed);
}
도움이 되었습니까?

해결책

I would suggest using the character controller that comes with the standard assets. It takes care off all fps movements out of the box.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top