为了在Unity中获得更流畅的控制(点击并按住),我应该进行哪些更改?

问题描述 投票:0回答:1

我一直在尝试使我的代码在Y轴上平滑移动(例如,在IOS游戏中-> Space Frontier),但是它的抖动绝对不好,也不平滑。我应该如何尝试?我想向上移动的播放器具有2D刚体,

`公共类MovementOnTouch:MonoBehaviour

public float currentVelocity = 0.0f;
public float accelerationRate = 0.0079f;
public float decelerationRate = 3.0f;
public float initialVelocity = 1.0f;
public float finalVelocity = 2.0f;

// Update is called once per frame
void Update()
{
    for (int i = 0; i < Input.touchCount; i++)
    {
        if (Input.touchCount > 0)
        {
            currentVelocity = currentVelocity + (accelerationRate * Time.fixedDeltaTime);
            transform.Translate(0, currentVelocity,0 ); //
        }
        else
        {

            currentVelocity = currentVelocity - (decelerationRate * Time.fixedDeltaTime);
            if (currentVelocity > 0)
            {
                transform.Translate(0, currentVelocity,0 ); //
            }
            else
            {
                transform.Translate(0, 0, 0);
            }
        }
        currentVelocity = Mathf.Clamp(currentVelocity, initialVelocity, finalVelocity);
    }
}

}`

2d touch tap taphold
1个回答
0
投票

不要用于(int i = 0; i

尝试这样的事情

if (Input.GetMouseButtonDown(0)) {
//accelerate
} else {
//do something else
}

© www.soinside.com 2019 - 2024. All rights reserved.