Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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 FuryFight3r · May 21 at 06:02 AM · rigidbodyaddforce

Issues when using Rigidbody force to Move/Carry Objects

Hi all, I am having some issues when changing my Object Carrying Method from a Static Locked position attached to the player to a more fluent movement that also has physics so carried objects cannot phase through walls etc. The issue I am facing while using this is that the object if placed under the Player and then picked up it levitates the player up into the sky, is there a way that while an object is being carried it ignores only the players collider, while still being able to crash into walls and other objects?


The other issue I am having with this is that the object never seems to settle at the carry position, it always overshoots it's mark and is constantly 'bouncing' back and forth around the carrying position.


The coding I am using to move the object toward its position while being carried is as follows:

 void moveObject()
     {
         if (isSmallOBJ)
         {
             if (transform.position != smallDest.position)
             {
                 if(distance < 0.05f)
                 {
                     Vector3 f = smallDest.position - transform.position;
                     f = f.normalized;
                     f = f * lowForce;
                     rig.AddForce(f);
                     distance = Vector3.Distance(transform.position, smallDest.position);
                 }
                 else if (distance < 0.5f)
                 {
                     Vector3 f = smallDest.position - transform.position;
                     f = f.normalized;
                     f = f * midForce;
                     rig.AddForce(f);
                     distance = Vector3.Distance(transform.position, smallDest.position);
                 }
                 else if (distance < 5f)
                 {
                     Vector3 f = smallDest.position - transform.position;
                     f = f.normalized;
                     f = f * highForce;
                     rig.AddForce(f);
                     distance = Vector3.Distance(transform.position, smallDest.position);
                 }
                 else
                 {
                     dropObject();
                 }
             }
         }
         else
         {
             if (distance < 0.05f)
             {
                 Vector3 f = dest.position - transform.position;
                 f = f.normalized;
                 f = f * lowForce;
                 rig.AddForce(f);
                 distance = Vector3.Distance(transform.position, dest.position);
             }
             else if (distance < 0.5f)
             {
                 Vector3 f = dest.position - transform.position;
                 f = f.normalized;
                 f = f * midForce;
                 rig.AddForce(f);
                 distance = Vector3.Distance(transform.position, dest.position);
             }
             else if (distance < 5)
             {
                 Vector3 f = dest.position - transform.position;
                 f = f.normalized;
                 f = f * highForce;
                 rig.AddForce(f);
                 distance = Vector3.Distance(transform.position, dest.position);
             }
             else
             {
                 dropObject();
             }
         }
     }


Showcasing the Issues

Youtube Video

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
0

Answer by DenisIsDenis · May 22 at 04:50 AM

UnityEngine has a function:

     Physics.IgnoreCollision(colliderPlayer, colliderObject, true);

to disable collision of these two colliders, and:

     Physics.IgnoreCollision(colliderPlayer, colliderObject, false);

to enable collision of these two colliders.


When you pick up an object, you need to use the first function for all players and all colliders of the lifted object, and the second function - when throwing the object.


The moveObject() function code can be simplified:

 void moveObject()
 {
     if(isSmallOBJ)
     {
         if (transform.position != smallDest.position)
         {
             if (distance < 5)
             {
                 rig.velocity = Vector3.zero;
                 rig.MovePosition(Vector3.Lerp(rig.position, smallDest.position, Time.deltaTime * 15));
             }
             else
             {
                 dropObject();
             }
         }
     }
     else
     {
         if (distance < 5f)
         {
             rig.velocity = Vector3.zero;
             rig.MovePosition(Vector3.Lerp(rig.position, dest.position, Time.deltaTime * 15));
         }
         else
         {
             dropObject();
         }
     }
 }

In this code, the object does not tremble in different directions.


Also, the MovePosition() function takes into account physics, so the interaction with other objects will be correct.

Comment
Add comment · Show 3 · 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 FuryFight3r · May 30 at 06:28 AM 0
Share

I truly don't know what the heck is going on with this website, the last 2 weeks its near impossible to even post a question for the last week or more I've been trying to reply to this answer and the stinking website does nothing, I click 'Submit' to add my comment and the button then greys out and does nothing, this is so frustrating, what's the bet it actually lets this comment post?!??!

avatar image FuryFight3r FuryFight3r · May 30 at 06:31 AM 1
Share

ofcourse -.- SIGH.... Im going to post the comment I've been trying to post for the last week in a paste bin link, this is ridiculous it just will not let me post it >:(

https://pastebin.com/ZHUgAu90

avatar image DenisIsDenis FuryFight3r · Jun 01 at 03:53 AM 0
Share

True, my method does not allow you to throw an object. But you can disable the collider for all child objects in the loop:

 void SetCollisionState(bool isDisableCollision)
 {
     var collidersOfObject = rig.GetComponentsInChildren<Collider>();
     var collidersOfPlayer = this.GetComponentsInChildren<Collider>();
     foreach (var playerCollider in collidersOfPlayer)
     {
         foreach (var objectCollider in collidersOfObject)
         {
             Physics.IgnoreCollision(objectCollider, playerCollider, isDisableCollision);
         }
     }
 }

This code loops through all the object's colliders with all the player's colliders and turns collision on or off.

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

AddForce to position on Rigidbody 2 Answers

Confusion with AddForce with ForceMode.Acceleration 1 Answer

How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers

raycast hit add force problem, help needed please 1 Answer

Calculate forces required to rotate around an arbitrary point regardless of center of mass position 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