Car with Physics Simulation: Control Individual Wheels
-
Introduction
In an earlier article, you learned how to steer or drive a car with physics simulation.
Sometimes you may need to control the 4 wheels individually. For example, you might want to turn them to different directions. You’ll learn how to do that in this article.
Set Wheel Directions Individually
You can use the following block to set the direction of each wheel:
The first 4 inputs are the direction values for each of the 4 wheels: LF (left front), RF (right front), LB (left back) and RB (right back). Usually, you should put in direction values between -90 and 90 degrees.The last input is the name of the physics-based car. You can leave this input blank if the car is already the selected sprite object.
For example, the following block will turn the 4 wheels to 45 degrees and -45 degrees, so that they form a circle path:
The wheels will look like this:
Set Engine Force for Each Wheel Individually
You can use the following block to set the engine force for each wheel:
The first 4 inputs are the engine forces applied to each of the 4 wheels: LF (left front), RF (right front), LB (left back) and RB (right back). If it is positive, that wheel will roll forward; if it is negative, then that wheel will roll backward.The brake level is set for the entire car, which is the percentage the speed will reduce each time this block runs.
The last input is the name of the physics-based car. You can leave this input blank if the car is already the selected sprite object.
For example, this block will drive the 2 left wheels forward and the 2 right wheels backward: