It seems like you can’t AddTorque to a RigidBody2D attached by SliderJoint2D to another RigidBody2D?!
I’m trying to make a car. I have a box shaped rigidbody that is the body of the car. Then I attach a circle shaped rigidbody to it via a slider joint. Then I try to add torque to the rigidbody in order to spin the wheel, but nothing happens!
Alternatively everything works fine if I use a spring joint instead of a slider joint. And everything works fine if I use a hinge joint instead of a slider joint.
So why doesn’t SliderJoint2D play nicely with AddTorque?
I have the same problem. I’d like to connect the wheels to the body using spring joints (for the suspension) and slider joints (so that the spring will only move up and down, and not sideways). After adding slider joints, adding torque to the wheels does nothing…
Attach a "wheel"to your car by using a Spring Joint and also a Slider Joint. But let’s call this wheel the “hub”.
The hub will respond nicely as the suspension of your car but the hub won’t rotate. So we need to put a tire on that hub and then we’ll able to rotate the tire.
Duplicate your hub circle body to be used as a tire. Attach the tire to the hub via a Hinge Joint. But now the tire will badly collide with the car body, so we need to make the tire exist on a different layer.
Create 2 layers. Name one layer “car_body”. Name the other layer “car_tires”. Associate your tire GameObjects with the tire layer. Associate the rest of your car GameObjects with the car body layer. Now go to the Unity preferences and specify that these two layers should not collide.
Now you can successfully AddTorque to your tire RigidBody2D.
One extra tip for you guys. My “hub” does NOT have a CircleCollider2D on it, but my “tire” does have a collider. Also I don’t know if it matters but I made my hub half the size (radius) of my tire.
Did you use the same weight for every rigidbody or use real values or what? I’m having some problems adjusting the suspension for different setups. At this point I 'm just going to assume my problem could be fixed adjusting some distances or weight values. I’ll spend some more time today tinkering
@Kurius : Thanks for the useful description. It seems that at least with Unity 4.5.2 the “hub” has to have a collider (set to trigger) to ensure that the car body is abled to rotate properly. Without an attached collider the rotation of the parent-car body seems to be fixed/locked…
Would anyone be willing to upload a demo showing exactly how they’ve setup their car? I’ve been struggling for months now trying to make a decent car on physics 2D that has a suspension. Any help would be very very appreciated.
I’ve Done a Short video on this, Showing how to setup a basic car, but i have a bug, that is i have to give negative force to the wheels in order to go forward:
On this second video i show how to solve this negative force problem
But i’m not sure about wich one of the two aproachs is the correct one to make a car xD