Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by aidan7501 · Mar 06, 2019 at 08:53 PM · physicsrigidbodyvelocityjoints

Pickup and carry rigidbody

I am trying to pickup and carry a rigidbody weapon, where it will move to a point in front of the player, and move with the player like a child object would, but still react to physics. Right now, I am simply setting the velocity to move towards the position, and adding the player's rigidbody velocity to the weapon movement velocity. When I do this, the weapon moves to the correct spot, but when I move around, the weapon jerks around. I want it to stay at the spot once it gets to that point. Here's a video showing the problem. This is the code I have...

 void FixedUpdate() 
     {
         if (beingHeld) 
         {
             rb.velocity = ((holdPosition - rb.position + (playerObj.GetComponent <Rigidbody>().velocity / Time.deltaTime / 1500)) * Time.deltaTime * 1500);        
         }
     }


Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by WarmedxMints · Mar 06, 2019 at 09:07 PM

Take a look at this open source project I worked on. We made a physics gun similar to that found in garrys mod. github What I did was create a vector at a point where the gun grabs the object and then calculate the direction and force to get the object to that point.

Comment
Add comment · Show 5 · 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 aidan7501 · Mar 06, 2019 at 09:17 PM 0
Share

@Warmedx$$anonymous$$ints I tried this out, and the problem that I'm having is that the rigidbody is lagging behind the point, so when I move while ai$$anonymous$$g down my sights, the sight is never in the middle of the screen, is this something that occurred in your project?

avatar image WarmedxMints aidan7501 · Mar 06, 2019 at 09:21 PM 0
Share

Not really. I set it up so the rigidbody mass effects how quickly it moves to the grab point. Something with a mass of 1 will move almost instantly whereas something will mass of 10 will get dragged and move slower. That was intentional in the gun project. Fork the git and try it out.

avatar image aidan7501 WarmedxMints · Mar 06, 2019 at 10:27 PM 0
Share

Hm I'm still not sure, I have the mass of the weapon object set to 1, and I use this code to move the object...

 void FixedUpdate() 
     {
         if (beingHeld) 
         {
 
             Vector3 holdPosition = positionTo$$anonymous$$oveTo;
             Vector3 toPos = holdPosition - transform.position;
             Vector3 forcePos = toPos / Time.fixedDeltaTime / rb.mass;
 
             rb.velocity = Vector3.zero;    
             rb.AddForce (forcePos, Force$$anonymous$$ode.VelocityChange);
 
 
         }
     }

It looks like it moves instantly to the position, but then when I walk around it's lagging behind. Am I doing this correctly?

Show more comments

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.

Follow this Question

Answers Answers and Comments

191 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 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 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 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 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 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 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

Problem Trying to Apply Non-Kinematic Velocity to Rigidbody 0 Answers

Velocity Movement & Physics Interactions by Rigidbody2D 0 Answers

Inconsistent Rigidbody2D velocity. 0 Answers

Can an ArticulationBody be joined to a Rigidbody? 1 Answer

What is the best way to create a balance board? 1 Answer


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