• 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 /
  • Help Room /
avatar image
Question by kubajs · Mar 19, 2020 at 08:51 PM · movementconfigurable joint

Spring or configurable joint - fluent moving of connected rigidbody

HI guys, I'm trying to fluently move connected rigidbody using spring or configurable joint when player rotates around the Y axis.

Basically I grab an item on mouse down and drag it until mouse up triggers. I'm pratically trying to simulate the object drag and drop from Stranded Deep survival game (for those who know it).

My problem is Fixed update is not sufficient for this operation - the jittering of the connected rigidbody is pretty visible = rotating player in FixedUpdate is not a good option. Not sure whether there is a way to move/sync the physics of the connected rigidbody with the player transform in Update. I tried to use Physics.SyncTransforms method just before rotating the player transform without any success.

Only the way I'm able to do the movement more fluent is shortening of the fixed update interval significantly which would highly probably lead to a considerable performance loss.

Every advice is welcome!

Comment

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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by kubajs · Mar 20, 2020 at 12:00 AM

Setting interpolation for carried rigidbody has completely fixed the problem.

However I just found a better overall solution for carrying items anyway.

Attaching the first draft code for those interested:

 using UnityEngine;
 
 public class ItemCarrying : MonoBehaviour
 {
     [SerializeField] private Transform _grabHolder;
     [SerializeField] private float _grabReach = 4f;
     [SerializeField] private float _followSpeed = 5f;
     [SerializeField] private float _carriedItemAngularDrag = 10f;
     [SerializeField] private Transform _camera;
 
     private bool _carrying;
     private Rigidbody _carriedRigidbody;
     private Vector3 _offset;
     private float _originalAngularDrag;
 
     private void Update()
     {
         //also use layer mask to avoid colliding with character controller or other collider which is part of player
         if (Input.GetMouseButtonDown(0) && Physics.Raycast(_camera.position, _camera.forward, out RaycastHit hit, _grabReach))
         {
             _carriedRigidbody = hit.collider.GetComponent<Rigidbody>();
             if (_carriedRigidbody)
             {
                 _carrying = true;
                 _offset = hit.point - _carriedRigidbody.transform.position;
                 _originalAngularDrag = _carriedRigidbody.angularDrag;
                 _carriedRigidbody.angularDrag = _carriedItemAngularDrag;
             }
         }
         else if (Input.GetMouseButtonUp(0) && _carrying)
         {
             _carrying = false;
             _carriedRigidbody.angularDrag = _originalAngularDrag;
             _carriedRigidbody = null;
         }
 
         if (_carrying)
         {
             _carriedRigidbody.velocity = (_grabHolder.position - _offset - _carriedRigidbody.transform.position) * _followSpeed;
         }
     }
 }
 
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

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

Simple Challenge ? moving a row of Cubes in Updateloop - they dont align exactly and cause jittering spaces between them 0 Answers

Movement worked yesterday but doesn't anymore? I did not make any changes in script 2 Answers

why OnMouseDown is not working 0 Answers

8 Directional movement animations for mobile 0 Answers

How can I get the player to face the direction it is going in a Unity 2D Game?,How do I make it so that my character faces in the direction it is facing in a 2D Unity Game 0 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