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 BurnatK · Sep 29, 2017 at 02:19 PM · unity 5pickupmoveposition

Carrying object with MovePosition shaking/vibrate

Hello,I have the possibilty to pick up object, carry them and drop them. That works but while I carrying my object it's shaking. I am using MovePosition in FixedUpdate() I tried several thing but I can't fix it. Have you an idea how to resolve it ?
thanks !

here some part on my code :

Update() :

 void Update () {
         
         if(carrying) {
 
             // the desired position on our carrying object
             carryPosition = mainCamera.transform.position + mainCamera.transform.forward * distance;
 
             // to avoid possibility the carrying object through the ground
             if (carryPosition.y <= distY) {
                 carryPosition.y = distY;
             }
             carriedObject.GetComponent<Rigidbody> ().velocity = Vector3.zero;
             carriedObject.GetComponent<Rigidbody> ().angularVelocity =Vector3.zero;
 
  
             // if click on mouse, we drop the carrying object
             checkDrop();
 
             // if the object enter in collision with a wall we drop the object
             checkCollision ();
         } else {
             // pick up the object front of the camera
             pickup();
         }
     }

FixedUpdate():

 void FixedUpdate(){
     
         if (carrying) {
             //Move our carrying object to the carryPosition
             carriedObject.GetComponent<Rigidbody> ().MovePosition (carryPosition);
         }
     }

PickUp() :

 void pickup() {
         if(Input.GetMouseButtonDown(1)) {
             int x = Screen.width / 2;
             int y = Screen.height / 2;
 
             Ray ray = mainCamera.GetComponent<Camera>().ScreenPointToRay(new Vector3(x,y));
             RaycastHit hit;
             if(Physics.Raycast(ray, out hit)) {
 
                 // all object which can be pick up have Pickupable.cs as script
                 Pickupable p = hit.collider.GetComponent<Pickupable>();
                 pick = p;
 
                 // if there is an object pickupable and the distance between the camera and the object is less than distance
                 if(p!=null && Vector3.Distance(p.gameObject.transform.position, mainCamera.transform.position) < distance) {
                     
                     carrying = true;
                     carriedObject = p.gameObject;
                     p.gameObject.GetComponent<Rigidbody>().useGravity = false;
 
                     // rotate the object to the defaut rotation
                     p.transform.rotation = Quaternion.identity;
 
                     float YOrigin = p.GetComponent<Collider> ().bounds.center.y;
                     float YMin = p.GetComponent<Collider> ().bounds.min.y;
 
                     // the distance from the center of the object to the bottom of the object
                     distY = YOrigin - YMin;
                 }
             }
         }
     }

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Bilelmnasser · Sep 29, 2017 at 02:56 PM

hi, Make your carried Object a child Of Your Carrying Object.

use Transform.SetParent , than it will move along her parent (remember to set her local position / rotation Once the object parent is set ), no need to extra script setting the position every frame

and to drop it just detach it from her parent :)

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

Answer by Litleck · Sep 29, 2017 at 05:07 PM

You could use mathf.lerp or matf.smoothdamp. Not sure if this will help much but if you have any questions let me know.

Comment
Add comment · 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 BurnatK · Sep 30, 2017 at 07:47 AM 1
Share

Thanks for the answer, I tried it's better with Lerp but still shaking, set the carriedObject a child of the player is working well

avatar image
0

Answer by conceptfac · Oct 17, 2020 at 10:57 PM

Here the same happens! Even localRotation or not! I'm trying to rotate objec in X and Y axis, but only -Y, +Y and -X is working when i rotate +X it shakes

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

Follow this Question

Answers Answers and Comments

142 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

Related Questions

How to give smooth constant move to a player object 1 Answer

Rigidbody Position Changes don't work when moving. 0 Answers

How do I stop my objects from going through walls when I pick them up and drop them down? 2 Answers

Combat begins when colliding with the enemy 1 Answer

Unity5 Enlighten Shadows 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