Hi, I’m working on a chassis and I’m using cylindrical constraints for the wheels, and I’m trying to make them turn/steer when the player makes the values of a VehicleSeat change…
But my code is not working
Code:
local att = script.Parent.Body:WaitForChild("AttachmentFL")
if script.Parent.VehicleSeat.SteerFloat == 1 then
att.Orientation = Vector3.new(0,30,-90)
print("it worked")
end
It doesnt print any output, and there’s no errors in the output.
When I take away the If statement, it works fine.
So maybe the If statement causes it to brake? But then how would I only run the said code when the VehicleSeat values change?
btw – script.Parent.VehicleSeat.SteerFloat.Value doesnt work
local att = script.Parent.Body:WaitForChild("AttachmentFL")
while wait(.1) do
if script.Parent.VehicleSeat.Steer == 1 then
att.Orientation = Vector3.new(0,30,-90)
print("it worked")
end
end
try this
dont check for steerfloat you gotta check for the steer value
i dont know how to explain that sorry but anyways if you check the vehicle seat there is a value called throttle and steer those get updated when player inputs
so
if seat.Steer==1 then
--car go right
elseif seat.Steer==-1 then
--car go left
elseif seat.Steer==0 then
--car no turn
end
im not sure if my code is correct or no cuz i dont remember which one turns which way lol
That’s not how you do turning with constraints, Usually with constraints you will utilize hinge constraints then set the target angle like so, not change the attachment orientation:
--input steer is the steer throttle goes from [-1,1]
constraint.TargetAngle = ChassisStats.TurnRadius.Value * inputSteer -- hinge
I suggest looking at the basic car kit (tells you how to rig it mostly) and the open source car chassis (complete rig with some neat features and easy to read and fix up code in my opinion) for how constraint vehicles work.
Another option is Sleitnicks tutorial which is more comprehensive for both rigging the car and coding it.
@slietnick, Says to change the orientation of the attachment, to change the wheel direction in his tutorials (I cant get help with this from his tutorial though, because I’m making a slightly different chassis)
I’m using cylindrical constraints to power the wheels, and changing the front two wheels attachments orientations to change the direction the vehicle goes in.
Basically you need to tell when the function is fired,or when it can be fired.Its basically not a looped function so it functions only once and it does not work probably as the game may not load and the script loaded before.You can fix it by this script:
local att = script.Parent.Body:WaitForChild("AttachmentFL")
local function changeorienttion()
if script.Parent.VehicleSeat.SteerFloat == 1 then
local success,errormessage = pcall(function()
att.Orientation = Vector3.new(0,30,-9)
end)
if success then
print("it worked")
else
print(errormessage)
end
end
end
You basically need to tell when to fire it to.
Use this line in script to fire it.