- Home /
Why are a rigidbody's freeze constraints not working?
I have a rigidbody that is not kinematic and its constraints are frozen but when I collide with a kinematic rigidbody, the rigidbody with the frozen constraints starts moving its position like a force has been applied to it? Why is this? Do the position constraints not work?
UPDATE
I found that it is not when the ridigbody collides with another, but when its parent (a character controller) stops moving that the rigidbody still continues to move.
Answer by highpockets · Dec 19, 2013 at 12:15 AM
Wether parented or not, Rigidbodys will always will always be their own entity. I had this problem once and I chose to add a fixedJoint to the 2 Rigidbodys instead of parenting them. That is one solution. That might not work for you in your case. Another option would be to find out when your character stops and in turn set the velocity of the child that needs to stop moving to (0,0,0).
Hope that helps and if it doesn't, I will try to help you find another solution.
The fixedJoint solution is not a good solution for my project, but I do see how it would work.
I have tried setting the velocity to zero on every update, but it still moves. And I have found out that it only experiences this problem when I have moved some distance from the initial starting position. So far, the only solution I have is setting the local position to the position I need it to stay at.
On a side note, I have found that setting a gameObject's transform position to itself is causing some floating point errors as the value does not stay the same. This might be the source of the problem I am experiencing, since my rigidbody is deep in a hierarchy and the compounding error would be causing it to move.
I'm a bit confused why you want to parent an object that isnt supposed to move to a character collider, which I assume is moving a lot during runtime. This is surely causing the problem. Is the rigidbody with the freeze constraints applied to an object that moves or rotates or gets affected by physics in any way other than with a collision? If it only needs to collide, you should maybe just use a primitive collider or mesh collider (more expensive than primitive collider's, but represents the mesh more accurately).
If the freeze constraints are being switched on and off during runtime, You could be running into bit wise issues. A way to solve that problem is to switch all position/rotation/scale constraints on or off at the same time. FreezeConstraints.All
Answer by ChrisGeorge · Dec 19, 2013 at 08:56 PM
The project I am working on is a modified version of the Bootcamp unity demo from the asset store. I have a soldier model that has a character controller and skeleton hierarchy. The skeleton hierarchy does not have rigidbody components. I have added a game object to each hand that have a sphere collider and rigidbody. These are the rigidbodies that move without me saying so after I have stopped moving the soldier's character controller.
I thought that the freeze constraints were being toggled before and had them set to the FreezeContraints.All every update, but that did not help either. The only thing that works besides re-positioning them every update is to make them kinematic, but I cannot do this because I need to do collision detection.