• Camera collisions with MyCalcView?
    2 replies, posted
Hey guys! I'm currently trying to make MyCalcView collide with walls, but I can't get it to work. If you guys could help me out, that would be great! Code: [CODE]function MyCalcView( ply, pos, angles, fov ) local view = {}; local dist = 100; local trace = {}; local total = ( angles:Forward()*80)-(angles:Up()*-10)-(angles:Right()*15) trace.start = pos; trace.endpos = pos - total * dist ; trace.filter = LocalPlayer(); local trace = util.TraceLine( trace ); if( trace.HitPos:Distance( pos ) < dist - 10 ) then dist = trace.HitPos:Distance( pos ) - -1; end; view.origin = pos-( angles:Forward()*40)-(angles:Up()*-10)-(angles:Right()*-.2) * dist view.angles = ang; view.fov = fov; view.drawviewer = true [/CODE] Result: [IMG]http://i.imgur.com/GsTiqw2.jpg[/IMG]
The problem is your trace start position and your order of operations on your last origin calculation. Your angle offsets should match from your trace end to your final origin calculation, but you have three different numbers between the two. Also, you are only multiplying the "dist" variable to the right vector of the final origin since the multiplication operator has priority over subtraction. You can save a lot of work by using the HitNormal of the trace instead to get the direction of the surface from the eyes instead of recalculating all of the angular limits. Ex. [code]local offset_forward = 80 local offset_up = 10 local offset_right = -15 local pullout = 4 local function MyCalcView(ply, pos, angles) local view = { origin = pos + angles:Forward() * offset_forward + angles:Up() * offset_up + angles:Right() * offset_right, } local trace = util.TraceLine({ -- Start from the eyes start = pos, -- Goto the final desired offset endpos = view.origin, filter = ply }) -- Something in the way if (trace.Hit) then -- Change the position to be in front of the surface -- By pulling out of the hit position in the direction of the trace view.origin = trace.HitPos + trace.HitNormal * pullout end; view.drawviewer = true return view end[/code]
my god, you're a saint! thank you! <3
Sorry, you need to Log In to post a reply to this thread.