我一直在尝试使我的代码在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);
}
}
}`
不要用于(int i = 0; i 尝试这样的事情if (Input.GetMouseButtonDown(0)) {
//accelerate
} else {
//do something else
}