【问题标题】:How to move a sphere over a distance in Unity 3D?如何在 Unity 3D 中将球体移动一段距离?
【发布时间】:2012-06-19 13:35:41
【问题描述】:

我只想与球体发生碰撞。我有两个球体,其中一个球体移动到另一个球体。一开始它们之间有一个距离,假设距离为 5。(假设 sphere1 和 sphere2)。当 sphere1 撞击到 sphere2 时,sphere2 必须仅移动 5 个单位。并且这种碰撞必须根据物理规则实现。如何我可以这样做吗?我尝试了很多东西,但我对统一 3D 很陌生。因此我找不到方法。谢谢你的帮助。

【问题讨论】:

    标签: c# unity3d geometry physics collision


    【解决方案1】:

    为了让物理学有意义,并在任何距离做同样的事情,我认为你需要 sphere1 向 sphere2 加速,(或者以足够的能量开始 10 个单位加上它所经历的任何摩擦) 在立即停止的同时转移它的所有能量,然后你需要 sphere2 在它被击中后以相同的速度减速。

    自己移动它可能更简单,使用简化或卡通化的物理学,比如球体以恒定的速度移动,直到它们移动到必要的距离。

    【讨论】:

      【解决方案2】:

      您是否尝试过类似的方法:

      using UnityEngine;
      using System.Collections;
      
      public class MovingSphere : Monobehavior // Attatch to sphere1
      {
          public GameObject sphere1, sphere2; // Set these in the inspector
          // Say sphere1 is at (-2, 0, 0)
          // Say sphere2 is at ( 0, 0, 0)
      
          void Update( )
          {
              if(sphere2.transform.position.x < 5) // If x-position of sphere2 < 5
              {
                  sphere1.transform.Translate(0.1f, 0, 0); // Moves the first sphere
              }                                            // positively on the x-plane
          }
      }
      

      我刚刚写了这个,所以它没有经过测试......但是它应该是这样的:

      START SCENE:
      
       [x] [-2] [-1] [00] [+1] [+2] [+4] [+5]
      (s1)           (s2)
      
       [x] [-2] [-1] [00] [+1] [+2] [+4] [+5]
           (s1)      (s2)
      
       [x] [-2] [-1] [00] [+1] [+2] [+4] [+5]
                (s1) (s2)
      
       [x] [-2] [-1] [00] [+1] [+2] [+4] [+5]
                     (s1) (s2)
      
       [x] [-2] [-1] [00] [+1] [+2] [+4] [+5]
                          (s1) (s2)
      
       [x] [-2] [-1] [00] [+1] [+2] [+4] [+5]
                               (s1) (s2)
      
       [x] [-2] [-1] [00] [+1] [+2] [+4] [+5]
                                    (s1) (s2) <Stop>
      

      如果第二个球体在被击中时发疯,您可能需要锁定 y 轴和 z 轴,这可以通过检查器窗口中的一个小复选框来完成。

      如果您需要更多信息,请告诉我们!

      【讨论】:

      • 我现在改变了我的方式,尝试另一件事。无论如何谢谢:)
      猜你喜欢
      • 2022-07-07
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-03
      相关资源
      最近更新 更多