你好。
我是Unity新手,我在实验他们的学习项目。
我完成了第一个火箭项目并决定尝试一下它,实验一些新的东西。但是,我遇到了一个奇怪的bug,船穿过我认为是一个非常厚的墙。我最初想做一些会有相当薄的墙的迷宫。 我在另一个项目上遇到了一个非常相似的问题,我试图制作一个很长时间以前的项目。这同样的抖动移动,物体穿过坚实的材料。

这是发生什么事的短视频描述:
https://imgur.com/a/arjahgy

这是运动代码:

首先检查游戏手柄是否有运动输入:

  Vector2 stickDirection = moveDirectionAction.ReadValue<Vector2>();
  if (stickDirection.sqrMagnitude > 0.01f)
  {
      targetDirection = stickDirection.normalized;
      isMoving = true;
  }

然后

  if (isMoving)
  {
      // 使用缓慢的转向(Slerp)平滑旋转向目标方向
      transform.up = Vector3.Slerp(transform.up, targetDirection, rotationSpeed * Time.deltaTime);
      // 
      // 杀死碰撞后物理旋转的惯性,以防止在放开时恢复旋转
      rb.angularVelocity = 0f;
      // 
      // 在玩家当前面对的方向上推进
      Vector2 thrustDirection = transform.up;


      float currentSpeed = rb.linearVelocity.magnitude;
      // 
      // 指数衰减
      float speedRatio = currentSpeed / maxSpeed;
      float dropoffMultiplier = Mathf.Exp(-3f * speedRatio); 
      // 
      // 增强逻辑
      bool isBoosting = boostAction.IsPressed();
      float currentThrust = isBoosting ? (thrustForce * boostMultiplier) : thrustForce;
      // 
      // 应用力
      float appliedForce = currentThrust * dropoffMultiplier;


      // 如果正在增强,则强制最高速度,否则正常最高速度
      float currentMaxSpeed = isBoosting ? (maxSpeed * 1.5f) : maxSpeed;


      if (currentSpeed > currentMaxSpeed)
      {
          rb.linearVelocity = rb.linearVelocity.normalized * currentMaxSpeed;
      }
      rb.AddForce(thrustDirection * appliedForce);
  }

首先,运动是快速的,我添加了旋转速度。
然后,击中墙/小行星后,旋转船,放开时,它继续从击中小行星时旋转,之前我旋转它时使用控制器。因此,我必须杀死惯性。
我不使用任何增强功能,在我的屏幕记录中,这种行为从开始就存在,甚至在我使用控制器之前(当船只向鼠标光标移动时)。

我觉得这是一个简单的修复/设置,但作为一个新手,我真的很迷惑:D

感谢大家的帮助。