所以我编辑了我的问题,因为我忘记给你看一个相机脚本。也许问题就在那里。我只是相信,即使在编辑旧问题之后,也绝对不会有人阅读编辑后的文章。所以我创建了一个新问题。
所以我有这样的问题。我试着让电车动起来。为此,我从 Asset Store“Bezier Path Creator”下载了一个脚本:https ://assetstore.unity.com/packages/tools/utilities/b-zier-path-creator-136082 。它很好用。之前需要创建第三人称相机。在写了一个简短的脚本后,我看到车辆在加速后开始抽动。我坐了几天试图解决这个问题,我看到了一件事。如果删除* Time.deltaTime,则不再有抽搐,但对 FPS 有依赖性(这是可以预见的)。此外,如果单击暂停按钮并逐帧查看,则不会出现抽搐。我该怎么办?
有一些代码我有问题:
switch (acceleration) {
case -1:
acc = -12F;
break;
case -2:
acc = -15F;
break;
case -3:
acc = -18F;
break;
case 0:
acc = 0.000f;
break;
case 1:
acc = 9f;
break;
case 2:
acc = 12f;
break;
case 3:
acc = 17.1f;
break;
}
if (Input.GetKeyDown ("e")) {
acceleration++;
}
if (Input.GetKeyDown ("q")) {
acceleration--;
}
if (acceleration < -3) {
acceleration = -3;
}
if (acceleration > 3) {
acceleration = 3;
}
if (speed > 40.0f) {
speed = 40.0f;
saveSpeed = speed;
speed = saveSpeed;
} else if (speed >= 0.0f && speed <= 0.03f && acceleration == 0) {
speed = 0.0f;
} else if (speed <= 0.0f && speed >= -0.03f && acceleration == 0) {
speed = 0.0f;
} else if (speed <= 40.0f) {
speed += ((Time.time - startTime)/1000)*(-acc);
}
// Taking a piece of Asset Store code
transform.rotation = pathCreator.path.GetRotationAtDistance(distanceTravelled);
transform.position = pathCreator.path.GetPointAtDistance(distanceTravelled); // I guess the problem is somewhere there
所以有 Asset Store 脚本中的GetRotationAtDistance方法GetPointAtDistance:
慕桂英546537
相关分类