so whenever i switch keys from a to d quickly (fly_left and fly_right) or d to a, etc. it resets my orientation back to 0,0,0. i have a video showing the orientation property and a visual of the car. thanks for the help!!
local currentTilt = CFrame.new()
local frontbackTilt = math.rad(10)
local leftrightTilt = math.rad(15)
local clampedfrontbackTilt = math.clamp(frontbackTilt, -frontbackTilt, frontbackTilt)
local clampedleftrightTilt = math.clamp(leftrightTilt, -leftrightTilt, leftrightTilt)
local function tiltcar(p, action_name)
local align_orientation = zalek.car_body.AlignOrientation
local xRot, yRot, zRot = currentTilt:ToEulerAnglesXYZ()
if action_name == "fly_forward" then
zRot = zRot - clampedfrontbackTilt
elseif action_name == "fly_backwards" then
zRot = zRot + clampedfrontbackTilt
elseif action_name == "fly_left" then
xRot = xRot - clampedleftrightTilt
elseif action_name == "fly_right" then
xRot = xRot + clampedleftrightTilt
elseif action_name == "stop_fly_forward" or action_name == "stop_fly_backwards" then
zRot = 0
elseif action_name == "stop_fly_left" or action_name == "stop_fly_right" then
xRot = 0
end
currentTilt = CFrame.Angles(xRot, yRot, zRot)
align_orientation.CFrame = currentTilt
end
keys_event.OnServerEvent:Connect(tiltcar)
“stop_fly_?” is received after the opposing side’s “start_fly_?*”. There’s no state kept to see what input is active to prevent nullifying the opposite side’s math. You can either add variables to implement that or check if the rotation is actually leaning to the stopping side before zeroing the rotation.
perfect job mate. i added a config with w,a,s,d states and added 2 conditionals at the end and it seems to have done the trick. thanks very much for your help!!!
code solution:
local currentTilt = CFrame.new()
local frontbackTilt = math.rad(10)
local leftrightTilt = math.rad(15)
local clampedfrontbackTilt = math.clamp(frontbackTilt, -frontbackTilt, frontbackTilt)
local clampedleftrightTilt = math.clamp(leftrightTilt, -leftrightTilt, leftrightTilt)
local function tiltcar(p, action_name)
local align_orientation = zalek.car_body.AlignOrientation
local xRot, yRot, zRot = currentTilt:ToEulerAnglesXYZ()
if action_name == "fly_forward" then
zalek_data.config:SetAttribute("W", true)
zRot = zRot - clampedfrontbackTilt
elseif action_name == "fly_backwards" then
zalek_data.config:SetAttribute("S", true)
zRot = zRot + clampedfrontbackTilt
elseif action_name == "fly_left" then
zalek_data.config:SetAttribute("A", true)
xRot = xRot - clampedleftrightTilt
elseif action_name == "fly_right" then
zalek_data.config:SetAttribute("D", true)
xRot = xRot + clampedleftrightTilt
elseif action_name == "stop_fly_forward" then
zalek_data.config:SetAttribute("W", false)
elseif action_name == "stop_fly_backwards" then
zalek_data.config:SetAttribute("S", false)
elseif action_name == "stop_fly_left" then
zalek_data.config:SetAttribute("A", false)
elseif action_name == "stop_fly_right" then
zalek_data.config:SetAttribute("D", false)
end
if zalek_data.config:GetAttribute("A") and not zalek_data.config:GetAttribute("D") then
xRot = -clampedleftrightTilt
elseif zalek_data.config:GetAttribute("D") and not zalek_data.config:GetAttribute("A") then
xRot = clampedleftrightTilt
elseif not zalek_data.config:GetAttribute("A") and not zalek_data.config:GetAttribute("D") then
xRot = 0
end
if not zalek_data.config:GetAttribute("W") and not zalek_data.config:GetAttribute("S") then
zRot = 0
end
currentTilt = CFrame.Angles(xRot, yRot, zRot)
align_orientation.CFrame = currentTilt
end
keys_event.OnServerEvent:Connect(tiltcar)