Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';不要把力加到我的刚体上。C#。统一性_C#_Unity3d_Rigid Bodies - Fatal编程技术网

为什么';不要把力加到我的刚体上。C#。统一性

为什么';不要把力加到我的刚体上。C#。统一性,c#,unity3d,rigid-bodies,C#,Unity3d,Rigid Bodies,我有一个刚体,它有一个光线投射,它在计算点积,以确定它是否在斜坡上。然后我用点积来确定RB是否会超过一个斜率,如果它是剂量,那么它应该被向下推,使它回到地面上。问题是rb.AddForce不工作,但是Debug.Log(“PUSH DOWN”)被正确调用 感谢您的帮助。对不起,我的英语不好 if (Physics.Raycast(transform.position, Vector3.down, out slopeOvershoottInfo, rayH

我有一个刚体,它有一个光线投射,它在计算点积,以确定它是否在斜坡上。然后我用点积来确定RB是否会超过一个斜率,如果它是剂量,那么它应该被向下推,使它回到地面上。问题是rb.AddForce不工作,但是Debug.Log(“PUSH DOWN”)被正确调用

感谢您的帮助。对不起,我的英语不好

if (Physics.Raycast(transform.position, Vector3.down, 
                    out slopeOvershoottInfo, rayHitdistance, whatIsGround))
{
      float  dot = Vector3.Dot(new Vector3(velocity.x, 0, velocity.z).normalized, slopeOvershoottInfo.normal);
        
      float roundedDot = Mathf.Round(dot * 1000) / 1000;// i do this because the dot changes large decemel increments even when on an even slope, so i do this to prevent those slite osolations

      if (dot != 0 && roundedDot != oldDot)
      {
            rb.AddForce(Vector3.down * overshootingSlopePushdown, ForceMode.Impulse);
            Debug.Log("PUSH DOWN");
            oldDot = roundedDot;
      }
}

超调斜率pushdown的值是多少?可能有几个方面:1。使用
ForceMode.pulse
会考虑刚体的质量,因此可能会添加一个非常小的力。2. <代码>超调斜率下压太小,无法产生差异/质量太高。3.向下矢量3.down基本上会增加向下的力,所以它可能只是将rb撞到它下面的碰撞器上。4.可能不太可能,但您的rb可能是运动学的。4.您可能正在您的应用程序中的其他地方覆盖速度code@BugFinder该值为2。我试图增加到10左右,但这并没有改变任何事情。可能在一开始就应该添加这个,但当我在if语句中用点替换两个roundedDot时,它似乎在不断地向下推。