Hinge jointで考えてみました。
Hinge jointはグローバル座標でないとただしく動作しないので、
シーンに直接作成しています。
Sphereを作成してジョイントの代わりにPysicsコンポーネントを追加します。
Sphere1は物理の影響を受けさせたくないのでisKinematicをオンに
しておきます。
- Sphere1にRigidBodyコンポーネントを追加
- Sphere2,3,4にHinge jointを追加
- Hinge joint>Connected Bodyに親のジョイントを設定
次にCube1にHinge jointの親(Sphere1)にコンストレインさせるため
コンストレイン用のスクリプトを作成します。
using UnityEngine;
using System.Collections;
public class Constraint : MonoBehaviour {
public Transform tr;
private Quaternion rot;
// Update is called once per frame
void Update () {
this.transform.position= tr.position;
this.transform.rotation= Quaternion.Euler( tr.eulerAngles.x,
tr.eulerAngles.y,
tr.eulerAngles.z );
}
}
Sphere1にコンストレイントのコンポーネントを追加してターゲットにTransform(Cube1)を設定します。
シーンを再生してCube1,Cube2を動かすと確認できます。


0 件のコメント:
コメントを投稿