so basically im trying to make my car rotate around on the Y axis if im holding A or D and i also want it to tilt -15/15 degrees on the align orientations x axis. i’ve got the Y axis done but i’m just trying to make the car tilt now.
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)
local align_orientation = zalek.car_body.AlignOrientation
local turn_angle = (seat_turnspeed * 10) * (deltaTime)
local 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)
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)
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)
disconnectFunction()
elseif action_name == "stop_turncar_right" then
zalek_data.config:SetAttribute("D", false)
disconnectFunction()
end
end
turncar_event.OnServerEvent:Connect(manage_keys)
what i’ve got:
what i’m aiming for: