• the default Drive model of gmod seems to always noclip
    4 replies, posted
Hey, trying to make a vehicle out of the drive module to save time. I know that it's something obvious but can't really tell what it is, why does this movement code cause the entity to noclip everywhere instead of colliding with walls? [lua] StartMove = function( self, mv, cmd ) -- Set observer mode to chase, so the entity will be drawn. self.Player:SetObserverMode( OBS_MODE_CHASE ) -- -- Update move position and velocity from our entity -- mv:SetOrigin( self.Entity:GetNetworkOrigin() ) mv:SetVelocity( self.Entity:GetAbsVelocity() ) end, -- -- Runs the actual move. On the client when there's -- prediction errors this can be run multiple times. -- You should try to only change mv. -- Move = function( self, mv ) -- -- Set up a speed, go faster if shift is held down -- local speed = 0.0005 * FrameTime() if ( mv:KeyDown( IN_SPEED ) ) then speed = 0.005 * FrameTime() end -- -- Get information from the movedata -- local ang = mv:GetMoveAngles() local pos = mv:GetOrigin() local vel = mv:GetVelocity() -- -- Add velocities. This can seem complicated. On the first line -- we're basically saying get the forward vector, then multiply it -- by our forward speed ( which will be > 0 if we're holding W, < 0 if we're -- holding S and 0 if we're holding neither ) - and add that to velocity. -- We do that for right and up too, which gives us our free movement. -- vel = vel + ang:Forward() * mv:GetForwardSpeed() * speed vel = vel + ang:Right() * mv:GetSideSpeed() * speed vel = vel + ang:Up() * mv:GetUpSpeed() * speed -- -- We don't want our velocity to get out of hand so we apply -- a little bit of air resistance. If no keys are down we apply -- more resistance so we slow down more. -- if ( math.abs( mv:GetForwardSpeed() ) + math.abs( mv:GetSideSpeed() ) + math.abs( mv:GetUpSpeed() ) < 0.1 ) then vel = vel * 0.90 else vel = vel * 0.99 end -- -- Add the velocity to the position ( this is the movement ) -- pos = pos + vel -- -- We don't set the newly calculated values on the entity itself -- we instead store them in the movedata. These get applied in F inishMove. -- mv:SetVelocity( vel ) mv:SetOrigin( pos ) end, -- -- The move is finished. Use mv to set the new positions -- on your entities/players. -- FinishMove = function( self, mv ) -- -- Update our entity! -- self.Entity:SetNetworkOrigin( mv:GetOrigin() ) self.Entity:SetAbsVelocity( mv:GetVelocity() ) self.Entity:SetAngles( mv:GetMoveAngles() ) -- -- If we have a physics object update that too. But only on the server. -- if ( SERVER && IsValid( self.Entity:GetPhysicsObject() ) ) then self.Entity:GetPhysicsObject():EnableMotion( true ) self.Entity:GetPhysicsObject():SetPos( mv:GetOrigin() ); self.Entity:GetPhysicsObject():Wake() self.Entity:GetPhysicsObject():EnableMotion( false ) end end, [/lua] I am aware that this is the default code straight off the wiki but that's because I'm not sure what to change to make it not noclip.
Have you tried [url]https://wiki.garrysmod.com/page/Entity/SetCollisionGroup[/url] ?
this seems to allow collision, I'm pretty sure the issue was that it was SetPos'ing instead of setting velocity, which was making the entity setpos into walls regardless of collision group [lua] FinishMove = function( self, mv ) -- -- Update our entity! -- if ( SERVER && IsValid( self.Entity:GetPhysicsObject() ) ) then --self.Entity:GetPhysicsObject():EnableMotion( true ) self.Entity:GetPhysicsObject():SetVelocity( mv:GetVelocity() ) self.Entity:GetPhysicsObject():Wake() --self.Entity:GetPhysicsObject():EnableMotion( false ) end self.Entity:SetNetworkOrigin( mv:GetOrigin() ) self.Entity:SetAbsVelocity( mv:GetVelocity() ) --self.Entity:SetAngles( mv:GetAngles() ) -- -- If we have a physics object update that too. But only on the server. -- end, [/lua] not gonna lock the thread though cos someone might point out that this is a shit solution and come up with a better one EDIT: This skullfucks prediction when I put my server out of single player, makes the ship appear to have ~15 fps :/ what have I done wrong in prediction?
shameless self bump cos I am not smart enough.
Is FinishMove being called on both client & server? And try printing what velocity is being set on which tick #, make sure they all match up on both client & server
Sorry, you need to Log In to post a reply to this thread.