Make Gravity Gun Unfreeze specific entities

Hey, I want the GravGun to Unfreeze specific entities when left clicked. This is what I got so far:

hook.Add( "GravGunPunt", "UnfreezeGravGunnedEntities", function( ply, ent )
	if table.HasValue( pickupable, ent:GetClass():lower() ) then
		local phys = ent:GetPhysicsObject()
		if ( IsValid( phys ) ) then
			phys:EnableMotion( true )
end )

It is not working, so does anybody know what I’m doing wrong?

[editline]27th September 2015[/editline]

The table is defined above

If the object unfreezes once you touch it with any physical object (after punting the frozen object with the gravgun), then your problem is just that you need to call phys:Wake() after phys:EnableMotion()

[editline]27th September 2015[/editline]

EnableMotion(true/false) dictates if force is allowed to be applied to an object (be it gravity or object-to-object physics)

Setting it to true means it can accept forces, but the game engine optimizes by not considering gravity until an object touches it (or until Wake is called).

This make sense, thanks! :slight_smile:

Just tested it and it seems to work just fine. Thanks for your help! :slight_smile: