• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by thecoolracer · Jan 13, 2015 at 04:25 PM · physicsrigidbodypick uppick up object

Physics gun like in Garry's Mod?

Like in t$$anonymous$$s video https://www.youtube.com/watch?v=tx2mlbFu420

It looks like it works quite well, and actually, I could make it too. But I noticed that $$anonymous$$s 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.

Comment
AlucardJay
dakota52

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Laumania · Mar 01, 2019 at 03:46 PM

All you need you will find here :)

https://www.youtube.com/watch?v=ZnWfChctC9M

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) :)

Comment
Bunny83
WarmedxMints

People who like this

2 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by mhernandez88 · Jul 21, 2016 at 04:27 PM

T$$anonymous$$s 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

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HyblockerDevelopment · Aug 12, 2018 at 12:57 PM 0
Share

Actually no. The OP of the video stated on a reddit post:

" Nah, the rigidbody is enabled at all times. I needed the object to remain affected by physics while it was being held. If I were to simply parent the prop to a Transform then I would lose physics and it would start clipping through the map etc.

Setting it to kinematic as /u/Measuring mentioned wouldn't work as kinematic bodies don't have velocity and are unaffected by physics.

My solution was to disable the prop's gravity upon grabbing. It is moved around via velocity and thus remains as a fully physics intractable object. This gives me all the benefits of interacting with the physics engine in a fluid way (Collisions are normal, no addition calculation needed after throwing/releasing as it has velocity, etc) "

avatar image

Answer by jamezzz · Aug 12, 2018 at 01:25 PM

Dead thread time:

as @HyblockerDevelopment said, keeping the rigidbody enabled w$$anonymous$$lst 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 t$$anonymous$$s is an old thread but it's fun to answer.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Box collider on a moving object-shopping cart 3 Answers

Screen keeps doing flips after i added a rigidbody,My screen starts doing flips with rigidbody on my player when i turn around 2 Answers

Object jumping while moving(with addForce) 0 Answers

Collisions on children won't collide whilst there is a rigidbody on the parent object! 1 Answer

Detecting Input on ~100 Objects 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges