C# 当摄影机移动时,场景中的所有内容(除播放器外)看起来都很模糊| Unity2D

C# 当摄影机移动时,场景中的所有内容(除播放器外)看起来都很模糊| Unity2D,c#,android,unity3d,unity3d-2dtools,C#,Android,Unity3d,Unity3d 2dtools,我开始我的游戏时使用了一个简单的相机跟随脚本,它只在x轴上跟随我的玩家,带有偏移和一些限制 我在我的android上录制了一段视频来展示我的意思。在录制过程中,问题有点夸张(由于录制),只有当尖峰进入视图时才可见。不录制时,播放器动画非常平滑 然而,当第一次运行游戏时,一切看起来都“紧张不安”。尽管我所有的播放器物理都在固定更新中,输入内部更新和相机更新都在更新中。我试着将插值设置为在玩家刚体上进行外推。现在,当相机移动时,播放器的外观和动画都会变得平滑,但其他一切都会变得模糊。我想可能是我的脚

我开始我的游戏时使用了一个简单的相机跟随脚本,它只在x轴上跟随我的玩家,带有偏移和一些限制

我在我的android上录制了一段视频来展示我的意思。在录制过程中,问题有点夸张(由于录制),只有当尖峰进入视图时才可见。不录制时,播放器动画非常平滑

然而,当第一次运行游戏时,一切看起来都“紧张不安”。尽管我所有的播放器物理都在固定更新中,输入内部更新和相机更新都在更新中。我试着将插值设置为在玩家刚体上进行外推。现在,当相机移动时,播放器的外观和动画都会变得平滑,但其他一切都会变得模糊。我想可能是我的脚本或设置出了问题,所以我尝试关闭vsync,将目标帧速率设置为60,当一切都不起作用时,我下载了Cinemachine。即使使用cinemachine而不是我自己的脚本,它看起来仍然很模糊,我也不明白为什么。这是我的控件的简化版本

 private void Update()
 {
     //Handle touch input
     if (Input.touchCount > 0)
     {

         foreach (Touch touch in Input.touches)
         {
             switch (touch.phase)
             {
                 // Touchdown
                 case TouchPhase.Began:
                     if (onGround || !doubleJumped)
                     {
                         jump = true;
                         touchReleased = false;

                         if (onGround)
                             anim.SetBool("jump", true);
                     }
                     break;

                 //Touch up
                 case TouchPhase.Ended:
                     allowGlide = false;
                     anim.SetBool("glide", false);
                     if (rb.velocity.y > 0)
                         touchReleased = true;
                     break;
             }

         }
     }
 }


 void FixedUpdate()
 {
     rb.velocity = new Vector2(newMoveSpeed, rb.velocity.y);

     onGround = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
     if (onGround && !jump)
     {
         gliding = false;
         allowGlide = false;
         anim.SetBool("glide", false);
         anim.SetBool("jump", false);
         doubleJumped = false;
     }

     //Slowly Accelerate if not at top speed and touching the ground
     if (newMoveSpeed < moveSpeed && onGround)
         newMoveSpeed += 0.0165f;
     anim.speed = Mathf.Clamp(newMoveSpeed, 13, 18);

     //Jumping 
     if (jump && onGround)
     {
         jump = false;
         rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
     }
     else if (jump && !doubleJumped && !onGround)
     {
         jump = false;
         doubleJumped = true;
         allowGlide = true;
         rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
     }

     //Add multiplier if falling down
     if (rb.velocity.y < 0 && allowGlide)
     {
         anim.SetBool("glide", true);
         if (!gliding)
         {
             rb.velocity -= Vector2.up * Physics2D.gravity.y;
             gliding = true;
         }
         else
         {
             rb.velocity += Vector2.up * Physics2D.gravity.y * (glideMultiplier - 1) * Time.deltaTime;
         }
     }
     else if (rb.velocity.y < 0)
     {
         rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
     }

     //Increase fall multiplier if touch is released mid jump
     else if (rb.velocity.y > 0 && touchReleased)
     {
         rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
     }
     else if (rb.velocity.y == 0)
     {
         return;
     }
 }
private void Update()
{
//手柄触摸输入
如果(Input.touchCount>0)
{
foreach(输入触摸,触摸)
{
开关(接触相)
{
//触地得分
案例接触阶段。开始:
如果(onGround | | |!双跳)
{
跳跃=真;
touchReleased=false;
如果(每轮)
动画挫折(“跳跃”,真实);
}
打破
//修补
案件审理阶段结束:
allowGlide=false;
动画设置工具(“滑动”,假);
如果(径向速度y>0)
touchReleased=true;
打破
}
}
}
}
void FixedUpdate()
{
rb.velocity=newvector2(newMoveSpeed,rb.velocity.y);
onGround=物理2D.重叠圆(地面检查位置、地面检查半径、whatIsGround);
如果(旋转和跳跃)
{
滑翔=假;
allowGlide=false;
动画设置工具(“滑动”,假);
动画挫折(“跳跃”,错误);
双跳=假;
}
//如果不是以最高速度并接触地面,则缓慢加速
if(newMoveSpeed0&&touchReleased)
{
rb.velocity+=Vector2.up*Physics2D.gravity.y*(LowJump乘数-1)*Time.deltaTime;
}
else如果(rb.velocity.y==0)
{
返回;
}
}

谢谢,任何帮助或反馈都将不胜感激

您是否检查了设备上运行的游戏的帧速率?我有一个电影/动画背景(但对Unity来说是新的),在我看来,你有一个帧速率问题。尽管如此,如果录音软件改变了图形,我不确定我看到的和你看到的是一样的东西。为什么你的录音软件会这样做?你试过使用Rec吗?这对我很有用


很抱歉没有将此作为评论发布-我当前的代表不允许我发表评论。

可能我认为这会导致设备中的录制出现问题,这可能会占用一些计算能力并导致问题,播放而不录制时是否会发生同样的情况?

我没有看到您所说的任何“模糊”,但我知道您正在对每一帧进行光线投射,这可能会妨碍您的表演我也没有看到任何模糊,这就是东西移动时的样子请分享你的播放器移动脚本-可能是播放器的移动不平稳,所以相机会跳跃,导致背景不稳定。@Baxorr除非我遗漏了什么,否则你在固定更新中调用的是
Physics2D.Overlapcircle
。。这是一个光线投射操作。。。每个固定更新。。。ie每帧可能不止一次…@Baxorr np。根据你到底需要什么,可能有更好的方法。如果您只想知道根据播放器相对于地面的位置播放哪个动画。。。然后尝试检查玩家的
transform.position.y
是否比你场地的
y
+-阈值)低。这只是一个想法,也是许多想法中的一个。我刚刚检查过。由于某种原因,我的android设备的帧速率上限为30。但这似乎确实是个问题。我在pc上测试了帧速率,它看起来非常平滑,帧速率为120+fps。将其设置为60也很顺利,但我似乎无法更改Android上的帧速率上限。我会同意这看起来确实是您的问题。我不知道如何解决这个问题,或者这是否可能。我猜是这样
 private void Update()
 {
     //Handle touch input
     if (Input.touchCount > 0)
     {

         foreach (Touch touch in Input.touches)
         {
             switch (touch.phase)
             {
                 // Touchdown
                 case TouchPhase.Began:
                     if (onGround || !doubleJumped)
                     {
                         jump = true;
                         touchReleased = false;

                         if (onGround)
                             anim.SetBool("jump", true);
                     }
                     break;

                 //Touch up
                 case TouchPhase.Ended:
                     allowGlide = false;
                     anim.SetBool("glide", false);
                     if (rb.velocity.y > 0)
                         touchReleased = true;
                     break;
             }

         }
     }
 }


 void FixedUpdate()
 {
     rb.velocity = new Vector2(newMoveSpeed, rb.velocity.y);

     onGround = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
     if (onGround && !jump)
     {
         gliding = false;
         allowGlide = false;
         anim.SetBool("glide", false);
         anim.SetBool("jump", false);
         doubleJumped = false;
     }

     //Slowly Accelerate if not at top speed and touching the ground
     if (newMoveSpeed < moveSpeed && onGround)
         newMoveSpeed += 0.0165f;
     anim.speed = Mathf.Clamp(newMoveSpeed, 13, 18);

     //Jumping 
     if (jump && onGround)
     {
         jump = false;
         rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
     }
     else if (jump && !doubleJumped && !onGround)
     {
         jump = false;
         doubleJumped = true;
         allowGlide = true;
         rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
     }

     //Add multiplier if falling down
     if (rb.velocity.y < 0 && allowGlide)
     {
         anim.SetBool("glide", true);
         if (!gliding)
         {
             rb.velocity -= Vector2.up * Physics2D.gravity.y;
             gliding = true;
         }
         else
         {
             rb.velocity += Vector2.up * Physics2D.gravity.y * (glideMultiplier - 1) * Time.deltaTime;
         }
     }
     else if (rb.velocity.y < 0)
     {
         rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
     }

     //Increase fall multiplier if touch is released mid jump
     else if (rb.velocity.y > 0 && touchReleased)
     {
         rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
     }
     else if (rb.velocity.y == 0)
     {
         return;
     }
 }