- Home /
WheelJoint2D Local Axis
The Manual states that there is an Option for the suspension in the WheelCollider2D: Local Axis, Direction along which the suspension travels.
I did not see this option in the editor and i also cannot find it via the script.
So how exactly do i need to setup a WheelJoint2D so that it bounces straight up and down? (The angle does not seem to do the trick. The wheels jump around in every direction like a with a normal spring joint.)
Answer by taylank · May 28, 2014 at 09:53 PM
Do you have the WheelJoint on the wheel object itself? For a wheel, that means the suspension goes every which way as the wheel turns. You can either place the joint on the connected body instead, or fix the angle in every frame.
Doing this in Update() worked for me:
void FixSuspensionDirection () {
WheelJoint2D wheel = GetComponent<WheelJoint2D> ();
JointSuspension2D sus = wheel.suspension;
Vector2 facingDir = transform.InverseTransformDirection(wheel.connectedBody.transform.right);
float angleOffset = Mathf.Atan2(facingDir.y, facingDir.x) * Mathf.Rad2Deg;
sus.angle = angleOffset+90;
wheel.suspension = sus;
}
Thank you. Yes, i did find that solution too: jointSuspension = wheel.suspension; jointSuspension.angle = 90f + car.rotation.eulerAngles.z; wheel.suspension = jointSuspension;
I have my car object, some supension objects(with the WheelJoint) and then each of the wheels have a hinge-joint(i use for the motor). Is that maybe too much? It looks like my car is slightly jittering when it moves.
I'd remove the hinge joints, as WheelJoint2D comes with a motor you can use too. Also try changing the suspension frequency and/or damping to see whether it behaves more like you expect it to. It takes a lot of fiddling to get the right feel you are ai$$anonymous$$g for. I've found higher frequency and damping (stiffer suspension) works better for me but it could be different for your game.
Answer by ZANTcr · Aug 05, 2014 at 01:10 AM
Hi I did a 2D Vehicle Control for the asset store, in my script the WheelJoint2D are created automatic, but some tips for your vehicle 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.
Your answer

Follow this Question
Related Questions
64 bit Support for Unity? 1 Answer
How create a default setup for user? 0 Answers
Unity build with multiple .exe files 2 Answers