Wonky 2D Physics

I’m using the new 2D Wheel Joint and getting some strange results.

Example:

http://gfycat.com/InferiorNastyAdouri (boxes on wheels are just for visualization)

The code to drive all wheels:

	public class DriveControl : MonoBehaviour
	{
		public string axis = "Vertical";
		public float speed;

		public WheelJoint2D[] wheels;

		private void Update()
		{
			float rotation = Input.GetAxis(axis)*speed;

			foreach (WheelJoint2D wheel in wheels)
			{
				JointMotor2D motor = wheel.motor;
				motor.motorSpeed = rotation;
				wheel.motor = motor;
			}
		}
	}

Wheel Components:

alt text

Some of the specific issues I noticed:

  • Lots of jitter
  • The cart sometimes floats above on its hinge - as if gravity was very low
  • Strange acceleration
  • Wheels move along seemingly random axis, instead of straight up and down as set in the Wheel Joint suspension settings

Any ideas why this is happening?

Hi I did a 2D Vehicle Control for the asset store and some tips for your vehicle structure are:

Make your wheels child of the carbody. The carbody and the wheels need a rigidbody2d. In your carbody add 2 WheelJoint2D. In the WheelJoint2D drag and drop you wheel to connected rigidbody option. Adjust the anchor option of the WheelJoint2D. Your wheel object dont need WheelJoint2D, just your carbody.