Steer(angle, speed, wheelbase, track);
The Steer function simplifies the process of steering a four-wheeled vehicle by eliminating the necessity for complex coding. All that is required from you are four parameters: the distance between the front two wheels (track), the distance between the front and rear axles (wheelbase), the current speed of the vehicle, and the desired turning angle. This function then outputs the precise angle to rotate the front wheels.
If we suppose the wheels of your vehicle are labeled following the given example and that the axis of each wheel is set to the center point of rotation, you can calculate the parameters wheelbase and track as such:
wheelbase = Distance('wheel fr', 'wheel br');
track = Distance('wheel fr', 'wheel fl');
Here, ‘fr’ refers to ‘front right’, ‘fl’ corresponds to ‘front left’, while ‘br’ and ‘bl’ represent ‘back right’ and ‘back left’ respectively.
After these calculations, the Steer function can be invoked in the following manner:
frontWheelAngle = Steer(rz, py, wheelbase, track);
The ‘rz’ variable corresponds to the vehicle’s rotation around its Z-axis, which can be obtained through the Yaw function. The ‘py’ variable signifies the current speed along the vehicle’s directional Y-axis, usually extracted from the Acceleration function.
The output of the Steer function, frontWheelAngle, provides the angle needed to rotate the front wheels to accurately steer the vehicle. This output can be used to rotate your vehicle’s front wheels like so:
RotZ = frontWheelAngle;
In this instance, RotZ
is an animator’s variable that handles the rotation of an object around its Z-axis.
For a more comprehensive understanding, refer to the complete script following this animation video…
// declare objects to use
uses
'car', 'body',
'wheel fr', 'wheel br', 'wheel fl', 'wheel bl',
'wheel box fr', 'wheel box fl'
;
// Set default units
SetUnits(Meters);
SetAngleUnits(Degree);
// initialize variable(s)
if FirstPass then begin
wheelbase = Distance('wheel fr', 'wheel br');
track = Distance('wheel fr', 'wheel fl');
CurDist = 0;
frontWheelAngle = 0;
end;
// scripts for object(s)
case object of
'body':
begin
Look;
end;
'car':
begin
Accelerate(py, 17, 1, 9);
CurDist = py;
Yaw(-47, 8, 16);
Pitch(3.2, 11, 13.5);
frontWheelAngle = Steer(rz, py, wheelbase, track);
end;
'wheel box fr', 'wheel box fl':
begin
RotZ = frontWheelAngle;
end;
'wheel fr', 'wheel fl', 'wheel br', 'wheel bl':
begin
Spin(Xaxis, CurDist);
end;
end;