0

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

4

2 回答 2

1

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

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

于 2012-06-19T13:52:52.630 回答
0

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

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 轴,这可以通过检查器窗口中的一个小复选框来完成。

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

于 2012-06-24T16:37:26.887 回答