Hi, I’m trying to control a joint with the built-in JointMotor,
but nothing happens.
Here’s my code…
public static GameObject c1;
public static GameObject c2;
public static JointMotor m;
void Start() {
c1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
c1.transform.position = new Vector3(0f, 1f, 0f);
c1.transform.localScale = new Vector3(1f, 2f, 0.3f);
c2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
c2.transform.position = new Vector3(0f, 3.1f, 0f);
c2.transform.localScale = new Vector3(1f, 2f, 0.3f);
c1.AddComponent<Rigidbody>();
c1.rigidbody.mass = 1f;
c2.AddComponent<Rigidbody>();
c2.rigidbody.mass = 1f;
c1.AddComponent<HingeJoint>();
c1.hingeJoint.anchor = new Vector3(0f, 0.5f, 0f);
c1.hingeJoint.axis = new Vector3(1f, 0f, 0f);
c1.hingeJoint.connectedBody = c2.rigidbody;
c1.hingeJoint.useMotor = true;
m = new JointMotor();
c1.hingeJoint.motor = m;
}
void Update() {
m.force = 100f;
m.targetVelocity = 1000f; // just trying high numbers to be sure something happens, but nothing happens
}
…
Two cubes are created, their physics works and the HingeJoint work.
The motor doesn’t work though… No movement, the two cubes just fall to the ground.
It’s the same as if I would remove all the motor code.
Please help! Thank you