Help with Vehicle Steering

Hi, I’m working on a vehicle chassis, but I’m having problems with the steering, I’m trying to steer the wheels by checking the VehicleSeat Input, and then adjusting the orientation of the Attachment to the wheel, to steer.

Here’s my code: (Doesnt work)

   local steer = 30

while true do

        if seat.SteerFloat == 1 then
    		AttachmentFL.Orientation = Vector3.new(0, steer, -90)
    		AttachmentFR.Orientation = Vector3.new(0, steer, -90)
    	end
    	
    	if seat.SteerFloat == -1 then
    		AttachmentFL.Orientation = Vector3.new(0, -steer, -90)
    		AttachmentFR.Orientation = Vector3.new(0, -steer, -90)
    	end
    	
    	if seat.SteerFloat == 0 then
    		AttachmentFL.Orientation = Vector3.new(0, 0, -90)
    		AttachmentFR.Orientation = Vector3.new(0, 0, -90)
    	end
     wait()
end

What can I do to make this work?

Any help is much appreciated! :grinning: :+1:

You need to update on every frame after the user input update. Also, your code can be simplified to:

local STEER = 30

local function updateSteering()
    local orientation = Vector3.new(0, STEER * seat.SteerFloat, -90)
    AttachmentFL.Orientation = orientation
    AttachmentFR.Orientation = orientation
end

I’m already using a while true loop, and that doesnt work…

1 Like

If this doesn’t help you, then you probably incorrectly configured your attachments or are having errors in your values.

1 Like

I’m not getting any errors, Also I have already seen that video, and I’m trying to make a different/simplified chassis, and I can assure you I haven’t made any mistakes with my Attachments.

Also, if you look at my code, you can see its based off of that video…

1 Like

Your code is very inefficient because you are using if statements to direct your steering.
Print some values and ensure they are corresponding correctly, also describe your issue more in depth.

1 Like

I know, thats why I’m here (on the devforum) for help…

I’m trying to steer the wheels by checking the VehicleSeat Input, and then adjusting the orientation of the Attachment to the wheel by a certain amount of degrees, to make the wheel turn, thus, steering the vehicle…

1 Like

You should not use a while true do loop. Also, I only simplified your code, so it is no guarantee that it would work. You should play around with the function and test what it does and why it does not work (you might have mixed up an axis for example).

I have done that many times, My attachments are in the correct position, I know that for a fact, because when I don’t use the If statements the steering and everything works (but the vehicle then is not being controlled by the Vehicle Seat)

The steering works if you don’t use the if-statements?

Yes, But then I cant control it from the vehicle seat.

1 Like

What does that mean? The steering is not responding or what?

Yes, it means it doesnt respond… I cant control it from the vehicle seat (self explanatory)

1 Like

Can you send a gif or a recording because earlier you said that the steering works fine.

I don’t have any recording software… Maybe I can send an image? Idk how that would help…

Okay, that’s fine, but what do you mean by the statement that the steering works when you don’t use if-statements.

The script sets the orientation, and the wheels move… in said direction

Then something is wrong with either the STEER or the Seat.SteerFloat value, have you tried printing them

I set some prints, but for some reason nothing is printing now…

Can’t help you with the vague answers like that, sorry. Goodbye.