so i’m trying to make my hover car turn, i have my w,a,s,d inputs set up but i just have no idea how to turn the car. i tried putting an angularvelocity instance in my car’s primary part with an attachment but nope.
my code:
local function rotate_car(turn_speed)
local angular_vel = zalek_data.car_parts.body:WaitForChild("AngularVelocity")
angular_vel.AngularVelocity = Vector3.new(0, 0, turn_speed)
end
while i tried suphi’s code and applied it to mine it doesn’t really work. i think i have my car set up a little differently.
local function rotate_car(deltaTime, seat)
local align_orientation = zalek.car_body.AlignOrientation
turn_orientation = CFrame.fromOrientation(tiltX, seat.SteerFloat * seat.TurnSpeed * (deltaTime * 1000), tiltZ)
tilt_orientation = CFrame.fromOrientation(tiltX, 0, tiltZ)
align_orientation.CFrame = tilt_orientation * turn_orientation
end
if action_name == "connect" then
if not connection then
connection = rs.Heartbeat:Connect(function(delta)
rotate_car(delta, zalek_data.seats.control_seat)
end)
--print("connected")
end
end
hey craft; thanks a million for your help. so i havent worked on turning a car before; for one it seems to be very slow turning. as it rotates towards the 180 degree mark, the car tilts upwards somewhat and as i release my key, my car’s rotation goes back to normal and doesn’t save the position where i rotated to.
there’s a lot of problems so i’ll sort them out one by one.
local function rotate_car(deltaTime, seat)
local align_orientation = zalek.car_body.AlignOrientation
turn_orientation = CFrame.fromOrientation(tiltX, seat.SteerFloat * seat.TurnSpeed * (deltaTime * 1000), tiltZ)
tilt_orientation = CFrame.fromOrientation(tiltX, 0, tiltZ)
align_orientation.CFrame = tilt_orientation * turn_orientation
end
if action_name == "connect" then
if not connection then
connection = rs.Heartbeat:Connect(function(delta)
rotate_car(delta, zalek_data.seats.control_seat)
end)
--print("connected")
end
end
The issue I see is that you’re using an AlignOrientation. What that basically does is make the target object match a certain orientation. While it could work, the issue is that whenever you stop setting the position it must face it will reset back to it’s original position.
Personally I don’t have much experience with vehicles, but you’d probably want to try increasing the Velocity/MaxForce of the angular velocity in your original code.
If that doesn’t work out either, try experimenting with something like two linear velocities a certain offset ahead and behind a car that push left and right for turning.
solved. i just had to store the cframe (i didnt know how to lol)
local current_orientation = CFrame.new()
local frontbackTilt = math.rad(10)
local leftrightTilt = math.rad(15)
local connection = nil
local tilt_orientation = nil
local turn_orientation= nil
local tiltX = 0
local tiltZ = 0
local function disconnectFunction()
if connection then
connection:Disconnect()
connection = nil
end
end
local function rotate_car(deltaTime, seat, seat_turnspeed, rotAngle)
local align_orientation = zalek.car_body.AlignOrientation
local turn_angle = (seat_turnspeed * 10) * (deltaTime)
tiltX = rotAngle
turn_orientation = CFrame.fromOrientation(0, math.rad(turn_angle), 0)
current_orientation = current_orientation * turn_orientation
align_orientation.CFrame = current_orientation
end
local function manage_keys(p, action_name)
local align_orientation = zalek.car_body.AlignOrientation
if action_name == "turncar_forward" then
zalek_data.config:SetAttribute("W", true)
elseif action_name == "turncar_backwards" then
zalek_data.config:SetAttribute("S", true)
elseif action_name == "turncar_left" then
zalek_data.config:SetAttribute("A", true)
if not connection then
connection = rs.Heartbeat:Connect(function(delta)
rotate_car(delta, zalek_data.seats.control_seat, zalek_data.seats.control_seat.TurnSpeed, math.rad(-15))
end)
end
elseif action_name == "turncar_right" then
zalek_data.config:SetAttribute("D", true)
if not connection then
connection = rs.Heartbeat:Connect(function(delta)
rotate_car(delta, zalek_data.seats.control_seat, -zalek_data.seats.control_seat.TurnSpeed, math.rad(15))
end)
end
elseif action_name == "stop_turncar_forward" then
zalek_data.config:SetAttribute("W", false)
elseif action_name == "stop_turncar_backwards" then
zalek_data.config:SetAttribute("S", false)
elseif action_name == "stop_turncar_left" then
zalek_data.config:SetAttribute("A", false)
tiltX = 0
disconnectFunction()
elseif action_name == "stop_turncar_right" then
tiltX = 0
zalek_data.config:SetAttribute("D", false)
disconnectFunction()
end
end
turncar_event.OnServerEvent:Connect(manage_keys)