• Noclip with collisions
    2 replies, posted
Is it possible to be on noclip and collide with world? I googled it, but there was only something about uclip. I have added it to my gamemode but it doesn't work how I wish - it only slows down player when he comes close to a wall and then he goes through the wall. This is what I ripped from Uclip [CODE]maxrecurse = 4 maxloop = 50 local sv_noclipspeed = GetConVar( "sv_noclipspeed" ) function getNoclipVel( ply ) local noclipspeed = sv_noclipspeed:GetFloat() * 100 local forward = ply:KeyDown( IN_FORWARD ) local back = ply:KeyDown( IN_BACK ) local left = ply:KeyDown( IN_MOVELEFT ) local right = ply:KeyDown( IN_MOVERIGHT ) local jump = ply:KeyDown( IN_JUMP ) local duck = ply:KeyDown( IN_DUCK ) local speed = ply:KeyDown( IN_SPEED ) -- Convert the input to numbers so we can perform arithmetic on them, to make the code smaller and neater. local forwardnum = forward and 1 or 0 local backnum = back and 1 or 0 local leftnum = left and 1 or 0 local rightnum = right and 1 or 0 local jumpnum = jump and 1 or 0 local ducknum = duck and 1 or 0 local speednum = speed and 1 or 0 local vel = Vector( 0, 0, 0 ) vel = vel + ( ply:EyeAngles():Forward() * ( forwardnum - backnum ) ) -- Forward and back vel = vel + ( ply:EyeAngles():Right() * ( rightnum - leftnum ) ) -- Left and right vel = vel + ( Vector( 0, 0, 1 ) * jumpnum ) -- Up vel = vel:GetNormalized() vel = vel * noclipspeed if duck then vel = vel / 10 end if speed then vel = vel * 3 end return vel end -- Given a velocity, normalized velocity, and a normal: -- Calculate the velocity toward the wall and remove it so we can "slide" across the wall. function calcWallSlide( vel, normal ) local toWall = normal * -1 local velToWall = vel:Dot( toWall ) * toWall return vel - velToWall end local override_velocity -- This will be set as the current desired velocity, so we can later perform the movement manually. function zeromove() override_velocity = Vector( 0, 0, 0 ) end -- The brain of Uclip, this makes sure they can move where they want to. function checkVel( ply, move, vel, recurse, hitnorms ) if vel == Vector( 0, 0, 0 ) then return end -- No velocity, don't bother. local ft = FrameTime() local veln = vel:GetNormalized() hitnorms = hitnorms or {} -- This is used so we won't process the same normal more than once. (IE, we don't get a wedge where we have to process velocity to 0) recurse = recurse or 0 -- Keep track of how many recurses recurse = recurse + 1 if recurse > maxrecurse and maxrecurse > 0 then -- Hard break zeromove() return end local t = {} t.start = ply:GetPos() t.endpos = ply:GetPos() + vel * ft + veln -- Add an extra unit in the direction they're headed just to be safe. t.filter = { ply } local tr = util.TraceEntity( t, ply ) local loops = 0 while tr.Hit do -- Recursively check all the hits. This is so we don't miss objects behind another object. loops = loops + 1 if maxloop > 0 and loops > maxloop then zeromove() return end if tr.HitWorld or ( tr.Entity:IsValid() and tr.Entity:GetClass() == "prop_dynamic" ) then -- If world or a prop they don't own that they're not stuck inside. Ignore prop_dynamic due to crash. local slide = calcWallSlide( vel, tr.HitNormal ) override_velocity = slide if table.HasValue( hitnorms, tr.HitNormal ) then -- We've already processed this normal. We can get this case when the player's noclipping into a wedge. zeromove() return end table.insert( hitnorms, tr.HitNormal ) return checkVel( ply, move, slide, recurse, hitnorms ) -- Return now so this func isn't left on stack end if tr.Entity and tr.Entity:IsValid() then -- Ent to add! table.insert( t.filter, tr.Entity ) end tr = util.TraceEntity( t, ply ) end end local sbox_noclip = GetConVar( "sbox_noclip" ) function move( ply, move ) if ply:GetMoveType() ~= MOVETYPE_NOCLIP then return end if sbox_noclip:GetInt() == 2 then return end -- This allows servers to disable UClip by setting sbox_noclip to 2. local ft = FrameTime() local vel = getNoclipVel( ply ) -- How far are they trying to move this frame? override_velocity = vel checkVel( ply, move, vel ) if override_velocity ~= Vector( 0, 0, 0 ) then move:SetOrigin( move:GetOrigin() + ( override_velocity * ft ) ) -- This actually performs the movement. end move:SetVelocity( override_velocity ) -- This doesn't actually move the player (thanks to garry), it just allows other code to detect the player's velocity. return true -- Completely disable any engine movement, because we're doing it ourselves. end hook.Add( "Move", "UclipMove", move, ULib and 15 or nil ) -- If ULib is installed then set a low priority in its hook priority system.[/CODE]
[CODE]ply:SetMoveType( MOVETYPE_FLY )[/CODE]
MOVETYPE_FLY is what I have tried before Uclip and players complained about this movetype because you can easily block yourself on doors' edges and you have to practice how to fly Or maybe is it possible to make MOVETYPE_FLY start flying at full maxspeed and stop player instantly when he releases buttons like it is on MOVETYPE_NOCLIP?
Sorry, you need to Log In to post a reply to this thread.