Advertisement
TylerB

proper vehicle thirdperson / no props

Mar 4th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. ---------------------------------------------------------------------
  2. -- This script overrides garry's vehicle thirdperson view function
  3. -- so that props do not obstruct the camera
  4. --
  5. -- Place in lua/autorun/
  6. -- fuck the police
  7. ---------------------------------------------------------------------
  8.  
  9. --if SERVER then AddCSLuaFile() return end
  10.  
  11. timer.Simple( 1, function()
  12.     function GAMEMODE:CalcVehicleView( Vehicle, ply, view )
  13.  
  14.         if Vehicle.GetThirdPersonMode == nil then return end
  15.        
  16.         -- If we're not in third person mode - then get outa here stalker
  17.         if not Vehicle:GetThirdPersonMode() then return view end
  18.  
  19.         local mn, mx = Vehicle:GetRenderBounds()
  20.         local radius = (mn - mx):Length()
  21.         local radius = radius + radius * Vehicle:GetCameraDistance()
  22.  
  23.         -- Trace back from the original eye position, so we don't clip through walls/objects
  24.         local TargetOrigin = view.origin + ( view.angles:Forward() * -radius )
  25.         local WallOffset = 4
  26.              
  27.         local tr = util.TraceHull( {
  28.             start   = view.origin,
  29.             endpos  = TargetOrigin,
  30.             filter  = Vehicle,
  31.             mins    = Vector( -WallOffset, -WallOffset, -WallOffset ),
  32.             maxs    = Vector( WallOffset, WallOffset, WallOffset ),
  33.             mask    = MASK_NPCWORLDSTATIC
  34.         } )
  35.        
  36.         view.origin         = tr.HitPos
  37.         view.drawviewer     = true
  38.  
  39.         -- If the trace hit something, put the camera there.
  40.         if tr.Hit and not tr.StartSolid then
  41.             view.origin = view.origin + tr.HitNormal * WallOffset
  42.         end
  43.  
  44.         return view
  45.  
  46.     end
  47. end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement