6) More on Advanced Jointing
Starting with our original model... if we wanted to make the car move, we could replace the original rear hinges with motors. This would spin the wheels, but only in one direction. In our case we want both forward AND reverse, so we'll set up our two rear hinges as custom motors using the UI.
We'll start by selecting one of the rear wheel hinges and setting the accel value in the UI to one. This will allow it to spin on it's own. Next we'll set the controller value to "drive".
Repeat the same steps for the other rear wheel. Be sure to set the controller name exactly the same as the other, so they will work together when controlled with one slider.
Test the model now. Use the "drive" slider and be sure the wheels are spinning in the same direction.
If one wheel spins in the opposite direction as the other, edit your model and use the move tool to rotate one hinge completely around.
NOTE: DO NOT use the "Flip" command shortcut! Using the flip command on parts of models to be used with Sketchyphysics usually will not work! Many models are completely messed up when you start "flipping" things. Always rotate a hinge using the move tool!
Rotating a hinge using the MOVE tool to make it spin the same direction as the wheel on the other side:
Test the model again and make sure your rear wheels are spinning in the same direction. Move the slider left and right. You should now have forward and reverse on your car! If the car is out of control, or the wheels don't spin evenly, play around with the damp settings or lower the accel setting. I have found an accel setting of 1.0 and a damp setting of 1.0 seems to work well in this model. Next comes the steering.
This is a little more complex than the drive because we'll need to add some more geometry to our model and also a few more joints.
The basic concept is to place an object between the wheels and the body that will rotate horizontally.
The easiest way I have found is to add a pair of blocks to the front of the car.
NOTE: These blocks are SEPERATE groups. They are NOT part of the body or wheel groups, and they are NOT grouped to each-other!
Next we'll add a servo for each block. Group each servo and it's block, then joint-connect each servo to the body.
Now we'll need to use the UI to set the steering servos to behave as needed. Set each servo's min and max to -45 and 45 to limit their swing. Also set their controller name the same (I'm using "steering") so they'll work together.
The next step is to make the
wheels move with the steering blocks. So using the joint connector
tool, break the original connection of each wheels hinge to the body
(using SHIFT) and make a new connection to their steering block. (Using CTRL.)
The final thing we need to do is to modify the body so the wheels have some room to turn. (Wheel-wells.) Here's one way of doing this:
Notice that the body is now made of two grouped objects grouped together. The main body and the nose of the body. If I simply push-pulled the original body and left it as one shape, the geometry would still reflect a rectangle and the wheels would hit the "invisible" body left over, unable to turn.
Be sure to use the "show collision" option in the UI to shape your body until it works right.
One downside of changing the original body to two groups grouped together, is that by re-grouping the original group, it broke any joint-connections that were associated with it originally. We'll look at some troubleshooting below.
This is usually the point where people get frustrated with the model
because things bind up and parts fall off. So let's look at some
possible reasons for failure.
Stay calm, debug everything, and check your joint connections.
I changed the body from one group to two (grouped) groups, it broke the
original joint connections. So I had to re-joint connect the rear
to the "new" body and also re-joint connect the servos to the body as
well. Follow these next few steps when troubleshooting a stubborn model:
Anytime you explode a group, or group a group with another object (even a joint) the original joints connected to it will be broken!!!
If things don't move like they should, or it looks like joints are "stretching", they're probably binding against something. (Maybe something invisible...so DEBUG your geometry.)
When all else fails, there is NO SHAME in deleting a joint completely and replacing it with a new one.
If you want to reference the finished model, it can be found HERE.
Here's a tip when testing your car:
After you press RUN, and before you start moving it around, Right-click the body and set the camera to "FOLLOW". This will keep the car from running off your screen. So you can dedicate more time to troubleshooting, and less time zooming and panning to follow the car around.
Also note that this car is far from being complete, as all the joints need their accel and damp settings tweaked. So there is still a lot of work to be done, but now you should have the tools to make it through!