• How do I make a trail stay for a few seconds after the object is removed/broken?
    0 replies, posted
Hi, I'm working on a modification to a squirt gun SWEP, and I managed to use a few tutorials to so far make a weapon that shoots a prop with a trail behind it to mimic water being shot from a water pistol. So far it works, but the only problem is that the trail doesn't die out after the prop fired breaks on collision, it just disappears. How can I make it so that the trail stays for about a second after the prop breaks? Here's the code I used: function SWEP:ThrowChair( model_file ) -- If we're the client then this is as much as we want to do. -- We play the sound above on the client due to prediction. -- ( if we didn't they would feel a ping delay during multiplayer ) -- if ( CLIENT ) then return end -- -- Create a prop_physics entity -- local ent = ents.Create( "prop_physics" ) -- -- Always make sure that created entities are actually created! -- if ( !IsValid( ent ) ) then return end ent.trail = util.SpriteTrail( ent,0,Color(255,163,128,255) ,false, 1, 0, 0.3, 0.0025,"trails/tube.vmt") -- -- Set the entity's model to the passed in model -- ent:SetModel( model_file ) -- -- Set the position to the player's eye position plus 16 units forward. -- Set the angles to the player'e eye angles. Then spawn it. -- ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) ) ent:SetAngles( self.Owner:EyeAngles() ) ent:Spawn() -- -- Now get the physics object. Whenever we get a physics object -- we need to test to make sure its valid before using it. -- If it isn't then we'll remove the entity. -- local phys = ent:GetPhysicsObject() if ( !IsValid( phys ) ) then ent:Remove() return end -- -- Now we apply the force - so the chair actually throws instead -- of just falling to the ground. You can play with this value here -- to adjust how fast we throw it. -- local velocity = self.Owner:GetAimVector() velocity = velocity * 500 velocity = velocity + ( velocity ) -- a random element phys:ApplyForceCenter( velocity ) end
Sorry, you need to Log In to post a reply to this thread.