I have never made a car chassis, and today I did so. Everything works, mostly.
The front wheels (turning wheels) flip back and forth and act sluggishly when told to turn, if anyone could please help me fix this, that’d be great
Right now, you have a poor implementation of driving and steering.
Here’s a great example of proper driving and steering:
-- DRIVE LOOP
----------------------------------------
while true do
-- Input values taken from the VehicleSeat
local steerFloat = vehicleSeat.SteerFloat -- Forward and backward direction, between -1 and 1
local throttle = vehicleSeat.ThrottleFloat -- Left and right direction, between -1 and 1
-- Convert "steerFloat" to an angle for the HingeConstraint servos
local turnAngle = steerFloat * MAX_TURN_ANGLE
wheelHingeR.TargetAngle = turnAngle
wheelHingeL.TargetAngle = turnAngle
-- Apply torque to the CylindricalConstraint motors depending on our throttle input and the current speed of the car
local currentVel = getAverageVelocity()
local targetVel = 0
local motorTorque = 0
-- Idling
if math.abs(throttle) < 0.1 then
motorTorque = 100
-- Accelerating
elseif math.abs(throttle * currentVel) > 0 then
-- Reduce torque with speed (if torque was constant, there would be a jerk reaching the target velocity)
-- This also produces a reduction in speed when turning
local r = math.abs(currentVel) / MAX_SPEED
-- Torque should be more sensitive to input at low throttle than high, so square the "throttle" value
motorTorque = math.exp( - 3 * r * r ) * TORQUE * throttle * throttle
targetVel = math.sign(throttle) * 10000 -- Arbitrary large number
-- Braking
else
motorTorque = BRAKING_TORQUE * throttle * throttle
end
-- Use helper functions to apply torque and target velocity to all motors
setMotorTorque(motorTorque)
setMotorVelocity(targetVel)
wait()
end
(This script was located in the Building a Basic Car tutorial on the Developer Wiki.)
And this will make the front two wheels cease spinning around? Also, the cylindrical constraints no longer keep the car’s front wheels in place. I replaced them with prismatics, and everything is back to the way it started in the first place, with the front wheels spinning around. Here’s the new model with the script implemented
I eventually did some tweaking and added a prismatic constraint between the two front wheels, enabling only when the car wasn’t turning. This, however made the front suspension defunct. I am fine with this, as it is the only solution I have. If anyone else has solutions, that’d be really helpful.