Physics gun like in Garry's Mod?

Like in this video - YouTube

It looks like it works quite well, and actually, I could make it too. But I noticed that his rigidbody position stays relative to the point where you pick up the object. How could I make it do that?

I guess handling rotation would be pretty simple. Make it detect keypress. Pause mouselook. Translate mouse axis movement to object rotation. Done.

All you need you will find here :slight_smile:

I had a need for a Physics Gun too - but couldn't find it. So made one with help from the community (mainly a guy called WarmedxMints) :)

This post is old, but i thought I would answer it in theory.

The theory is you get the raycast target, and access it public attributes such that you can enable “isKinematic”. Then with the raycast you can begin to attach the objects transform to the players look position. When you disable the gun, you disable isKinematic and the object will fall.

If you wish to handle rotations you just do that in the same way.
if ( mutatingObject )
if ( button.ctrl )
vec3 = new Vector3( input.horizontal, input.vertical … blah )
target.rotation = vec3

Dead thread time:

as @HyblockerDevelopment said, keeping the rigidbody enabled whilst moving the object is critical to ensure you can’t drag objects through walls. In theory you could have an invisible gameobject (I WILL CALL THIS TARGET)at a fixed distance from the physGun at all times acting as a transform. Then when you pick up an object (using raycast to get the object as a reference), you can use Physics.AddForce() in the direction of the TARGET to move the gameobject towards where the physGun is looking but retaining collisions of the object with walls.

to use the scroll wheel to “push” and “pull” the object away from the player as you can do in garry’s mod, simply move the target gameobject away from the player on the movement of the scrollwheel.

sorry, again this is an old thread but it’s fun to answer.