- Home /
How to get suspension or wheels collider with the new 2D unity tools
I am trying to make motorcycle game and I want to have suspension of the wheels. In 3D there is wheels collider, but how to get wheels collider on RigidBody2D. I have tried combining joints to achieve this but with no result. I will be glad if someone give me some suggestions how to make suspension with the 2D rigidbody and tools.
I manage to get some kind of suspension with spring joint, but now the wheels are jiggering all the time and by adding hinge joint to empty in the center of the wheel I manage to make it move
The script for moving: using UnityEngine; using System.Collections;
public class Controller : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
float move = Input.GetAxis("Horizontal");
Debug.Log(move);
GameObject wheel1 = GameObject.Find ("wheel1");
GameObject wheel2 = GameObject.Find ("wheel2");
HingeJoint2D joint1 = wheel1.GetComponent<HingeJoint2D>();
HingeJoint2D joint2 = wheel2.GetComponent<HingeJoint2D>();
Joint$$anonymous$$otor2D motor1 = joint1.motor;
Joint$$anonymous$$otor2D motor2 = joint2.motor;
motor1.motorSpeed = move * 5000;
motor2.motorSpeed = move * 5000;
joint1.motor = motor1;
joint2.motor = motor2;
}
}
But again is so unrealistic any suggestions
Answer by RightHandedMonkey · Jun 06, 2014 at 08:15 PM
Try the new Wheel Joint 2D for objects in Unity 4.5.
If you know of a good tutorial on this as well I would appreciate information on it since I am trying to understand this topic myself.
Answer by ZANTcr · Aug 05, 2014 at 01:30 AM
Hi, like the first answer posted I recomend use the new WheelJoint2D of Unity 4.5. I did a 2D Vehicle Control for the asset store, in my script the WheelJoint2D are created automatic, but some tips for setup your vehicle with this new component 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.
Hey! thanks, u simply explained how to connect wheels with car body and joints etc...
But can u plz tell me, If I want to use motor of RearWheel and FrontWheel, then how would I Script it to get both wheels and apply motor force, suspension etc... to feel and see the car movement realistic.
For instance, you plz see the HillClimb Racing. HillClimb Racing Link