Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --@name vehicle_ventus
- --@author artybyte
- --@shared
- --@model models/hunter/blocks/cube2x2x2.mdl
- function IsNAN(n)
- return n ~= n
- end
- if CLIENT then
- --@include ventus.txt
- local ventus = require('ventus.txt')
- local inner_camera = false
- ventus.use_joystick = false
- ventus.int_camera = false
- ventus.cam_key_pressed = false
- local function init_3ps_cam()
- hook.add('calcview', 'artybyte_veh_view', function()
- if not render.isHUDActive() then return end
- -- Get the chair/seat entity your chip is linked to
- local seat = player():getVehicle()-- your seat entity reference here
- -- Make sure we're in the vehicle
- if not seat or not player():inVehicle() then
- return
- end
- local eyeAngles = seat:getParent():worldToLocalAngles(player():getEyeAngles())
- -- Convert angles to forward vector (but ignore roll/pitch for horizontal orbit)
- local forward = eyeAngles:getForward()
- local cameraPos = seat:getParent():localToWorld( -forward * 500 + Vector(0, 0, 100) )
- local view = {
- origin = cameraPos,
- angles = ((seat:getParent():getPos() - cameraPos):getAngle()),
- fov = 77,
- drawviewer = true
- }
- return view
- end )
- end
- local function deinit_3ps_cam()
- hook.remove('calcview', 'artybyte_veh_view')
- end
- hook.add('think', 'artybyte_veh_ventus_think_cl', function( )
- if ventus.cam_key_pressed ~= input.isKeyDown(KEY.V) then
- ventus.cam_key_pressed = input.isKeyDown(KEY.V)
- if ventus.cam_key_pressed then
- ventus.int_camera = not ventus.int_camera
- end
- if ventus.int_camera then
- init_3ps_cam()
- else
- deinit_3ps_cam()
- end
- end
- end )
- net.receive('gmveh_ventus', function( )
- local t = net.readTable()
- ventus.ignition = t.ignition
- ventus.cyclic_FB = t.cyclicFB
- ventus.cyclic_LR = t.cyclicLR
- ventus.throttle_up_down = t.throttleUD
- ventus.rear_rotor_blades_ang = t.steerLR
- end )
- end
- if SERVER then
- local VEH = { }
- VEH.DriverChairLocalPos = Vector(34.16, 13.90, -14.68)
- VEH.DriverChairLocalAng = Angle(0, -90, 5)
- VEH.CamAngles = Angle()
- VEH.TractionVector = Vector()
- VEH.mass = 1200
- VEH.ignition = false
- VEH.data = { ignition = false, cyclicFB = 0, cyclicLR = 0, throttleUD = 0, steerLR = 0 }
- VEH.starter_counter = 0
- VEH.last_force_pos = Vector(0, 0, 0)
- VEH.cl_nets = {
- throttle = 0,
- blade_L_up = Vector(),
- blade_R_up = Vector(),
- rear_rotor_ang = 0,
- blade_L_ang = 0,
- blade_R_ang = 0
- }
- local A = 1
- net.receive('gmveh_ventus_cyclic', function( )
- local t = net.readTable()
- VEH.cl_nets = t
- end )
- VEH.HUD = prop.createComponent(
- chip():localToWorld(VEH.DriverChairLocalPos),
- chip():getAngles(),
- 'starfall_hud',
- 'models/holograms/hq_tube_thick.mdl',
- true
- )
- VEH.HUD:setParent(chip())
- VEH.HUD:setColor(Color(0,0,0,0))
- VEH.DriverChair = prop.createSeat(chip():localToWorld(VEH.DriverChairLocalPos), chip():localToWorldAngles(VEH.DriverChairLocalAng), 'models/nova/jeep_seat.mdl', true)
- VEH.DriverChair:setParent(chip())
- VEH.DriverChair:setColor(Color(0,0,0,0))
- --VEH.testholo = hologram.create(chip():getPos(), chip():localToWorldAngles(Angle()), 'models/holograms/hq_sphere.mdl')
- --VEH.testholo:setScale(Vector(3, 3, 3))
- chip():setMass(VEH.mass)
- chip():setColor(Color(0,0,0,0))
- VEH.HUD:linkComponent(VEH.DriverChair)
- VEH.HUD:linkComponent(chip())
- hook.add('think', 'artybyte_veh_ventus_think', function()
- local Driver = VEH.DriverChair:getDriver()
- if Driver ~= nil then
- if isValid(Driver) then
- local w, a, s, d =
- Driver:keyDown(IN_KEY.FORWARD),
- Driver:keyDown(IN_KEY.MOVELEFT),
- Driver:keyDown(IN_KEY.BACK),
- Driver:keyDown(IN_KEY.MOVERIGHT)
- local ignition = Driver:keyDown(IN_KEY.RELOAD)
- local lmb, rmb = Driver:keyDown(IN_KEY.ATTACK), Driver:keyDown(IN_KEY.ATTACK2)
- local shift, space = Driver:keyDown(IN_KEY.SPEED), Driver:keyDown(IN_KEY.JUMP)
- local fb = ( w and 1 or 0 ) - ( s and 1 or 0 )
- local lr = ( a and 1 or 0 ) - ( d and 1 or 0 )
- local ud = ( shift and 1 or 0 ) - ( space and 1 or 0 )
- local steer = ( lmb and 1 or 0 ) - ( rmb and 1 or 0 )
- if ignition and not VEH.data.ignition then
- VEH.starter_counter = VEH.starter_counter + 1
- if VEH.starter_counter > 5 then
- VEH.starter_counter = 0
- chip():emitSound('buttons/lightswitch2.wav', 155, 255, 1, 0)
- chip():setColor(Color(255,0,0,0))
- if math.random(1, 50) == 4 then
- VEH.data.ignition = true
- chip():setColor(Color(0,0,0,0))
- end
- end
- else
- chip():setColor(Color(0,0,0,0))
- end
- if ignition ~= VEH.ignition then
- VEH.ignition = ignition
- if ignition then
- if VEH.data.ignition then
- VEH.data.ignition = false
- chip():setColor(Color(0,0,0,0))
- end
- end
- end
- VEH.data.cyclicFB = math.lerp(0.05, VEH.data.cyclicFB, lr)
- VEH.data.cyclicLR = math.lerp(0.05, VEH.data.cyclicLR, -fb)
- VEH.data.throttleUD = math.lerp(0.05, VEH.data.throttleUD, -ud)
- --VEH.data.throttleUD = math.clamp(VEH.data.throttleUD - ud*0.02, -1, 1)
- VEH.data.steerLR = math.lerp(0.05, VEH.data.steerLR, -steer)
- local physics = chip():getPhysicsObject()
- local blades_dir = (( ( VEH.cl_nets.blade_L_up ) + ( VEH.cl_nets.blade_R_up ) ) /2 ):getNormalized()
- blades_dir.x = math.round(blades_dir.x, 2)
- blades_dir.y = math.round(blades_dir.y, 2)
- blades_dir.z = math.round(blades_dir.z, 2)
- if IsNAN(VEH.TractionVector.x) then VEH.TractionVector.x = 0 end
- if IsNAN(VEH.TractionVector.y) then VEH.TractionVector.y = 0 end
- if IsNAN(VEH.TractionVector.z) then VEH.TractionVector.z = 0 end
- local force_up_pos = chip():localToWorld(Vector(0, 0, 75 + 9))
- local last_up_pos = VEH.last_force_pos
- local up_pos_delta = force_up_pos - last_up_pos
- VEH.WindResistance = -physics:getVelocity()*0.05
- -- MAIN rotor
- physics:applyForceOffset(VEH.TractionVector, force_up_pos - up_pos_delta)
- local hor_rot = physics:getAngleVelocity().z
- local brake_hor_rot = ( - hor_rot*0.1 * ( 1 - math.abs(VEH.cl_nets.tail_rotor_axis) ) ) * VEH.cl_nets.throttle
- -- TAIL rotor
- physics:applyForceOffset(chip():getRight() * chip():getMass() * ( 0.037 * ( -VEH.cl_nets.tail_rotor_axis + brake_hor_rot ) ) * VEH.cl_nets.throttle, chip():localToWorld(Vector(-304.7, 14.33, 51.91 + 9)))
- -- tail rotor force local point
- -- wind resistance. slowing down helicopter on speed.
- physics:applyForceOffset(VEH.WindResistance * physics:getMass() * 0.004, force_up_pos)
- local cyclic_nonzero = Vector(fb, 0, lr):getNormalized():getLength()
- --local targetTractionVector = ((chip():getUp()*0.2) * (blades_dir*(0.03 + ud*0.25)) + (blades_dir*VEH.cl_nets.throttle*0.2)) * VEH.cl_nets.throttle * chip():getMass() * 60
- local targetTractionVector = (( blades_dir * VEH.cl_nets.throttle * ( 0.16 + (VEH.data.throttleUD*0.05) ) ) ) * VEH.cl_nets.throttle * chip():getMass() * 60
- -- 0.05, 0.075
- -- very important to smooth swashplate raw resulting vector between blades to make flight stable.
- VEH.TractionVector = math.lerpVector( 0.05, VEH.TractionVector, targetTractionVector )
- --VEH.testholo:setPos(chip():getPos() + VEH.TractionVector * 3.0)
- A = A + 1
- if A == 3 then
- net.start('gmveh_ventus')
- net.writeTable(
- VEH.data
- )
- net.send()
- A = 1
- end
- VEH.last_force_pos = chip():localToWorld(Vector(0, 0, 75 + 9))
- end
- end
- end )
- end
Advertisement
Add Comment
Please, Sign In to add comment