因此,在过去的两个月里,我一直在修改我的PlayerController,使之成为基于刚体的,以便与刚体有更多的交互,即推送对象。这一切都进行得很好,直到我开始测试我的游戏在一个独立的构建。当v同步关闭时,我立即注意到背景中奇怪的抖动/口吃(玩家运行平稳)(在关闭v同步的情况下,我的计算机在300fps+运行游戏)。起初,我认为这与Cinemachine有关,我正在使用CinemachineFreeLook,但老实说,我现在还不确定是否是Cinemachine引起的抖动/口吃。值得注意的是,抖动/口吃不是恒定的,而fps似乎是恒定的,抖动/口吃可能会消失大约20秒,然后回来。显然,在过去的一周里,我做了大量的研究,并且阅读了大量关于FixedUpdate与更新的文章,但不幸的是,我没有任何运气。
我试图在这篇文章中添加尽可能多的信息,以便很好地理解我的项目,但是首先我已经尝试过的东西:
在下面的中,您可以看到我的两个移动脚本,一个是实际PlayerController的一部分,另一个是我为赤裸播放器编写的脚本。
void FixedUpdate() {
_isGrounded = Physics.CheckSphere(_groundChecker.position, GroundDistance, Ground, QueryTriggerInteraction.Ignore);
_inputs = Vector3.zero;
_inputs.x = Input.GetAxis("Horizontal");
_inputs.z = Input.GetAxis("Vertical");
_inputs.Normalize();
if (_inputs != Vector3.zero)
transform.forward = _inputs;
_body.MovePosition(_body.position + _inputs * Speed * Time.fixedDeltaTime);
}这是我为赤骨播放器控制器编写的脚本。
void FixedUpdate() {
if (pushControllerScr._pushBlocker) {
input = Vector3.zero;
} else {
input = new Vector3(InputManager.MainHorizontal(), 0, InputManager.MainVertical());
}
RunAxis();
inputDir = input.normalized;
inputDir.Normalize();
// Makes the player able to move, while not landing or being dead
if (!landState && !climbManagerScr.isClimbing) {
Move(inputDir, running);
}
}
void Move(Vector3 inputDir, bool running) {
if (inputDir != Vector3.zero) {
float targetRotation = Mathf.Atan2(inputDir.x, inputDir.z) * Mathf.Rad2Deg + cameraT.eulerAngles.y;
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref turnSmoothVelocity, GetModifiedSmoothTime(turnSmoothTime));
}
float targetSpeed = ((running) ? runSpeed : movementSpeed) * inputDir.magnitude;
stateInfoBaseLayer = _anim.GetCurrentAnimatorStateInfo(0);
if (stateInfoBaseLayer.IsTag("Climbing") || stateInfoBaseLayer.IsTag("Standing")) {
currentSpeed = 0f;
} else {
currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, GetModifiedSmoothTime(speedSmoothTime));
}
if (stateInfoBaseLayer.IsTag("AirIdle") && currentSpeed > walkSpeed) {
currentSpeed = walkSpeed;
}
velocity = transform.forward * currentSpeed + Vector3.up * _rb.velocity.y;
if (_capsuleCol.enabled) {
_rb.MovePosition(_rb.position + velocity * Time.deltaTime);
}
}这是我在我的PlayerController脚本中实际使用的
下面你可以看到一些抖动/口吃的画面。很难捕捉到它,因为使用任何像OBS这样的录音软件,我的游戏中的fps都掉到了抖动/口吃消失的程度。抱歉,电话录音,但这是唯一的办法。
最后,这是一张专辑,里面有一些相关的设置。音像专辑
发布于 2020-02-13 10:01:45
看着你的录音,它看起来好像是顺利的播放器和其他一切。
根据我的经验,99%的时间意味着抖动来自于相机没有被正确同步到玩家。
您似乎已经做了正确的事情,通常情况下,将组合在一起应该会很好:
CinemachineBrain应该更新FixedUpdateFixedUpdate中将力/更改应用于物理对象如果您同时执行所有3个,则无论vsync、帧率、固定增量时间等,这都应该顺利地工作。
显然,您的特定项目可能会有其他的东西使它变得一团糟;但是我已经看到这个问题无数次了,通常这些合并的步骤应该可以解决它。
https://stackoverflow.com/questions/60198257
复制相似问题