Vehicle won't work

Hello. I made this vehicle script specifically for a chassis I’m making.
However it doesn’t work.
SCRIPT:

-- configs
local topspeed = 120 -- in mph
local accel = 4 --(time it takes to reach 60mph, in seconds)
local tirefriction = 0.9 -- more friction = more grip
local rearaxlesteering = false
local steeringangle = 30

--------------------------------------------

local hinges = script.Parent.Parent.hinges
local fl = hinges.fl
local fr = hinges.fr
local rl = hinges.rl
local rr = hinges.rl
local flsteer = hinges.steering.flsteer
local frsteer = hinges.steering.frsteer
local rlsteer = hinges.steering.rlsteer
local rrsteer = hinges.steering.rlsteer

local sps = topspeed * 1.6666666

script.Parent.Changed:Connect(function(property)
	fl.AngularVelocity = sps * script.Parent.Throttle
	fr.AngularVelocity = sps * script.Parent.Throttle
	rl.AngularVelocity = sps * script.Parent.Throttle
	rr.AngularVelocity = sps * script.Parent.Throttle
	fl.TargetAngle = steeringangle * script.Parent.Steer
	fr.TargetAngle = steeringangle * script.Parent.Steer
	if rearaxlesteering == true then
		rl.TargetAngle = steeringangle * script.Parent.Steer
		rr.TargetAngle = steeringangle * script.Parent.Steer
	end
end)
1 Like

Hello, It is a bit hard to understand what Is the problem here. Does It give you any error code? did you debug It? As far as I see, I think you have a few spelling errors in my opinion in:

local rl = hinges.rl
local rr = hinges.rl

both of them are using

hinges.rl

maybe start the debugging process

script.Parent.Changed:Connect(function(property)
    if property == "Throttle" or property == "Steer" then
        -- Your code here
    end
end)

It may not even be your script. Here are some Constraint physics things to look at:

  • Are your HingeConstraint ActuatorTypes set to Servo for the steering and Motor for the wheels?
  • What are your torque values for the hinges? If they are 0 (or below 10000) the vehicle may not work.
  • Is the vehicle Mass really high? The higher the mass the higher the MotorMaxTorque will need to be.
  • Are any of the vehicle Parts Anchored? Of course the vehicle won’t move.
  • Are any of the wheels or steering Parts welded to the chassis?
  • Also you have an Accel variable for acceleration, but are you going to link it to the HingeConstraint.MotorMaxAcceleration?

This solved the problem partially:

Though the vehicle won’t steer…

If you want to PM me a simple version of the vehicle I’d be happy to take a look.

I might aswell just post it here anyways :melting_face:
verybrokenchassis.rbxm (12.9 KB)

There were a few issues.
The biggest was that you had the steering script referencing the fl instead of the flsteering hinge (as well as the others)
Having different Part Densities when you use Constraints is an issue. It affects the way they react to each other.

Hinges are a bit too springy for making steering. You could add an invisible rod using Attachments a couple of studs behind the steering HingeConstraints. This would keep both wheels at the same angle. The model I added shows how I use a Motor instead, which is a controllable weld. It stiffens up the steering quite a bit, and you can use offsets to create Ackerman steering angles (inboard wheel angles more than the outboard one. This will also work with your double wishbone suspension.

I tweaked some of the numbers for the springs and the hinges, and added them to folders (instead of a model) so they are easier to find.
I added a couple of changes to the script so it enables welds at the rear axles so they don’t swivel at all when the rear wheel steering is false.
I also made it so the script doesn’t have more code running than it needs to when controlling your steering and throttle (resetting the motors every input).

I also changed your wheels from Balls with Meshes to Cylinders. This helps with traction since there’s more contact, and it also means your wheels won’t contact other items in game since they stick out farther than they appear to. I increased Density as well as Friction on the wheels.

You’ll have to do some fine tuning but it should work better for you now.
verybrokenchassis.rbxm (17.8 KB)

How can I do that?

e

Add an Attachment at the same location as the steering one in the LH steering Part.
Move the Attachment 2 studs forward (or back, doesn’t matter).
Add another Attachment on the RH steering Part. Move it forward (or back).
Add a RodConstraint between the 2 new Attachments.

This links both the LH and RH HingeConstraints so they won’t turn at different amounts.
Have a look at the way I did it to get a visual, but don’t follow that setup since it controls the steering completely differently.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.