Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
2
Question by Mikhail94 · Mar 24, 2018 at 02:39 PM · rigidbodycolliderrigidbody collision

Rigibody constraints do not work. Still moves a little.

I have root object with rigibody only and with childrens with colliders. Such a hierarchy is due to the fact that root is spawn point for spawn objects and used to rotate them.

 Rigidbody(root)
 |-children(collider)
 |-children2(collider)
 ...

The problem is that root rigidbody with constraints (allowed only Y rotation) slightly shifted with each collision of his children with other obstacles. If "Is Kinematic == true" - all ok, coordinates are stable. But I need to rotate my root rigidbody with physics, to stop it if it children ran into obstacles.

Please help me. I have no idea why the restrictions do not work.

alt text

1.gif (41.4 kB)
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

4 Replies

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

Answer by Mikhail94 · Mar 24, 2018 at 04:17 PM

Solution after several hours of heavy searching and debugging.

 private void Start()
 {
     // \ (•◡•) /
     Rigidbody rb = target.GetComponent<Rigidbody>();
     rb.centerOfMass = Vector3.zero;
     rb.inertiaTensorRotation = Quaternion.identity;
 }

For details read

https://docs.unity3d.com/ScriptReference/Rigidbody-centerOfMass.html https://docs.unity3d.com/ScriptReference/Rigidbody-inertiaTensorRotation.html

Comment
Add comment · Show 4 · 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 ModLunar · Jun 08, 2018 at 03:54 AM 0
Share

Thank you so much! I hope this solves the problems I've been having, I've been trying to use Collision events ins$$anonymous$$d of Trigger events for my hitboxes and hurtboxes used for combat in my game, and the rigidbodies have been wiggling out of whack >.>

[EDIT] - While this wasn't my particular problem, it was interesting.. Not sure if it helped, but wow.. it turns out my collider wasn't big enough for the sword swiping in the animation.. Lol T_T

avatar image rbosse · Feb 16, 2019 at 07:57 PM 0
Share

Thanks for this. Something changed and all of the sudden, my constraints weren't working. Now this is. I'll add a TODO to see if I can find it out in the future.

avatar image michaelday008 · Mar 23, 2020 at 06:02 AM 1
Share

This was exactly what I needed to fix the issue. I encountered the issue while trying to implement pushable boxes in a level for a game. In case anyone wants to see a real world example of how this problem manifests, I made a YouTube tutorial demonstrating it here: https://www.youtube.com/watch?v=maIAiSRBEdE

avatar image tonymotion · Oct 01, 2021 at 10:23 PM 0
Share

Thank you! This saved me from running a rotation check and correction on every frame! Your hard work is helping me and others!! #communitySupport :-D

avatar image
0

Answer by ristophonics · May 27, 2019 at 04:24 PM

hmm this has not worked for me.

I was used a hinge joint to create a steering wheel assets that was working very well in Unity 5.6. I imported the asset to 2018.4 with the same configuration but the constraints no longer function as they did in 5.6. I used the above code and several variations to get it to properly constrain position and select rotations but none worked. Not sure what to do...

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 RHPOSITIVE · Jul 30, 2019 at 02:28 PM

I tried many things.. (I've also tried the recommendations here.) It didn't work. So, I write simple code. I know; It's a really UGLY method, but absolutely working.. Just attach to dynamic object.

 public class PositionCorrection : MonoBehaviour
 {
     GameObject positionHelper;
     WaitForSeconds phDuration = new WaitForSeconds(1f);
 
     void Start()
     {
         GameObject positionHelperParent = GameObject.Find("Position Helper Parent");
         if (positionHelperParent == null)
         {
             positionHelperParent = new GameObject("Position Helper Parent");
         }
 
         positionHelper = new GameObject("P.H. " + gameObject.name);
         positionHelper.transform.SetParent(positionHelperParent.transform);
 
         StartCoroutine(PositionFix());
     }
 
     IEnumerator PositionFix()
     {
         while (true)
         {
             if ((positionHelper.transform.position - transform.position).sqrMagnitude < .01f)
             {
                 transform.position = positionHelper.transform.position;
             }
             else
             {
                 positionHelper.transform.position = transform.position;
             }
 
             yield return phDuration;
         }
     }
 }

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 onurkiris05 · Apr 20 at 11:06 AM

I had the same issue with my enemies that using NavMeshAgent . Current solution in the 'Best Answer' didnt work for me.

Well after some digging into game, i found out that NavMeshAgent overrides transform.position so upon enemy death, adding this line 'navMeshAgent.enabled=false;' solved my problem.

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

169 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

Related Questions

How to ensure raycasts hit colliders inside of trigger colliders on objects that have a rigidbody? 0 Answers

Rigidbody Unwanted Drift 1 Answer

gameObject can't move and collide after setting it off and setting it on again. 0 Answers

problem with character colliding with objects 0 Answers

Collision with 3D model 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