My recent bug report has been closed as duplicate of:
If it doesn’t bother anyone, can I please ask that others upvote this bug for fixing? I am currently making a zero-G VR game, and this bug is absolutely game breaking for my project.
[EDIT clarification]
I was told in the support response email that my findings would assist with the bug fixing. I hope so. And I hope maybe we can encourage them to take a harder look at it sooner, before another half of a version goes by.
[EDIT2]
This bug has been active since Feb 2015. Since Unity 5.0.0 Priority 3. Severity 0. Are you kidding me with severity 0? What the hell is wrong with the physics engine that after a few minutes in my game, the player is vibrating at a magnitude of ~10% their body width? This is game breaking, it’s stupidly easy to replicate, and it’s sad to see that if I don’t act the sqeaky wheel, it will probably never get fixed.
[EDIT3]
Replication clarification:
New Scene
Empty GameObject
Attach Rigidbody, turn off Gravity
Attach child sphere (with collider)
Hit Play
In SceneView, select the parent object for inspection and observe ZERO MOVEMENT
Select child sphere
Move child in local space however you wish. Slide it up and down an axis a few times, that’s all it takes.
Select parent object again and observe NEW NON-ZERO LOCATION with ZERO MOVEMENT
(Having a second child object for visual reference of parent object’s location also helps to view the randomness and increasing intensity over time)
[EDIT4.8]
And if you don’t have an account, you should totally go sign up! It’s free and easy! And then you can post here about how much you agree with me that it’s absolutely ridiculous that this bug hasn’t even had its severity level defined in almost 2 years!!! Half of a version has gone by since then! D:
[EDIT5.5]
Post about how their support team had the nerve to close my legitimate bug report because it’s a duplicate of a bug that they didn’t even want to look at!
[EDIT6.1]
Vote it! Now! If we build enough votes, I can go harass them instead of you guys.
You say, you are ‘scaling rigidbodies’.
I bet there is a ‘work around’, a (better) way to avoid scaling a rigidbody (itself).
What are you trying to achieve?
I am not scaling a rigidbody. I am simply translating a child collider in local space. “My recent bug report has been closed as duplicate of:” The original author of the bug report I have linked was scaling.
[EDIT2]
I see you didn’t vote. C’mon, man. You already opened the link. It only takes 2 more seconds to click on the vote button. You’re most likely already logged in so… you should totally go do that now.
[EDIT3]
Moved edits to first post for better context
I did a quick test and was able to reproduce the issue, while also finding a fix and possible cause of the issue, which is the rigidbody centerOfMass.
When you move a child collider of a rigidbody, unity will automatically change the rigidbody center of mass, which seems to cause this change in the rigidbodies position possibly due to floating point error?
Here is my test script
Click for code
using UnityEngine;
public class TestRigidbodyCenterMassBug : MonoBehaviour
{
public bool setCenterOfMass;
Rigidbody myRigidbody;
Transform child;
void Awake()
{
myRigidbody = GetComponent<Rigidbody>();
child = myRigidbody.transform.GetChild(0);
//Setting a rigidbody center of mass tells unity not to automatically set it
//when detecting changes in the rigidbody, such as a child collider moving.
//This alone is enough to fix the bug.
if(setCenterOfMass)
{
//We set the center of mass to itself just to stop unity from automatically setting it.
//To get unity to start automatically setting it again, you need to call myRigidbody.ResetCenterOfMass()
myRigidbody.centerOfMass = myRigidbody.centerOfMass;
}
}
void Update()
{
child.Translate((Vector3.up + Vector3.left) * .1f);
Debug.Log("Center Mass After Translate = " + DetailedVector(myRigidbody.centerOfMass));
}
string DetailedVector (Vector3 vector)
{
return "(" + vector.x + ") (" + vector.y + ") (" + vector.z + ")";
}
}
If we use your example setup of having a empty gameobject with a rigidbody component and no gravity placed at the origin (0,0,0), and add a child sphere object with a collider, place this script on the empty gameobject with the rigidbody on it.
If setCenterOfMass is on, we will set the center of mass on awake, which basically tells unity to not automatically update the center of mass for us and you will notice the empty gameobject no longer jitters.
If setCenterOfMass is off, you will notice the debug logs showing the center of mass is changing due to the child object being translated, which seems to also cause the empty gameobject to jitter.
You can see unity talk about some center of mass stuff here
This is very handy information. Thank you for posting!
Unfortunately, when I implemented this, I found two problems.
On load, the rig is jittering already, and this did not fix it. I had to collide with another object before the jittering stopped. Though, it did indeed appear to remain stopped, unlike before.
The rig no longer rotates around the player’s head… which poses a smaller problem in itself, but we may be able to deal with that.
Being this is VR, the rotations now feel as though they occur around some arbitrary point in nearby space. I thought about how I could circumvent this without allowing Unity to do its thing. Perhaps maybe reset the center when the player begins rotation, and also when colliding with something… I have my doubts about the accuracy of doing it this way, but I’ll edit post after giving it a go.
Before implementing this, the jittering would increase in magnitude over time. Now it does not seem to. When colliding with an object, the jittering intensity resets to 0 (But as I said above, the jittering seems to begin even before the Awake function is called), though because it increases over time, it will eventually pick back up to obnoxious levels over a minute or so.
[EDIT]
A crazy thought just occurred to me. Do you suppose this jittering is actually part of some kind of “unstuck” system or the sort? It makes sense that the jittering will occur when the object is created if they have some kind of underlying system that moves the object around until it finds the “floor” maybe? Then when the child collider moves causing the center of mass to shift and the rigidbody to reinitialize physics, it just does it again because init? And maybe the logic simply adds to the current jiggle rate when it’s called, thus the steadily increasing intensity from being called repeatedly?
If that were the case, we just need a way to turn that behavior off somehow.
[EDIT2]
I see you didn’t vote either. Is literally everyone out of votes or something? Or does no one really care if the engine gets fixed or not? Not one of the current 140 views actually bothered to help out. 0/140… that’s not very encouraging, community.
[EDIT3]
void Awake()
{
rig = GetComponent<Rigidbody>();
if (rig == null)
{
throw new System.Exception("[PlayerController] Player Rig initialized without Rigidbody!");
}
Debug.Log("Setting center of mass");
// Set center of mass to itself so we prevent Unity from constantly trying to recalculate it
rig.centerOfMass = rig.centerOfMass;
}
void FixedUpdate()
{
// If we have any sort of angular velocity, reset center of mass (and center of rotation) to the player's head every so often.
//if (rig.angularVelocity.sqrMagnitude > 0.0001f && Time.time > resetCoMTime)
if (Time.time > resetCoMTime)
{
// Reset center of mass to player's head. (Doing this manually since this causes an error-prone update to the rigidbody, and automatic updates will cause a massive jitter)
rig.ResetCenterOfMass(); // This turns on auto-update as well
rig.centerOfMass = rig.centerOfMass; // Turn off auto-update for center of mass
Debug.Log("Reset CoM");
// Reset CoMTime
resetCoMTime = Time.time + 0.5f; // Wait another so often
}
}
Results of experiments:
The rig is always jittering when the scene loads.
Colliding with something will make the jittering stop
Resetting center of mass seems to do absolutely nothing to stop jittering
Applying angular velocity stops the jittering (which… come to think of it, might be correlated to collisions… since they would apply angular velocity)
After angular velocity dies down… the rig will begin to jitter noticeably after ~1 minute and 20 seconds.
Changes in velocity do not effect jittering
And best of all:
Removing the above code results in zero difference in behavior.
I have angular drag = 0.01, so perhaps the 20 seconds is what it takes for the drag to fully stop the rigidbody’s angular velocity, and it’s actually 1 minute until the jittering begins?
In any case, center of mass does not seem to be effecting my rig the way I thought it was.
Hmmm, perhaps this is a different bug after all?
For clarification:
When I say “not jittering anymore”, I actually mean the jittering has sunk to a level of ~0.000001f in constant positional movement… effectively immobile for all intents and purposes.
When I said “begin to jitter noticeably”, I meant that the jittering suddenly rose to a level of ~0.001f in constant positional movement, and slowly increasing from there… effectively not only visible, but very disruptive in VR.
[EDIT4]
Changed code to:
using UnityEngine;
public class AntiJitter : MonoBehaviour {
public Rigidbody rig; // Rig to apply anti-jitter to
private float tickTime = 0.0f; // Time at which antijitter is applied
private float tickSpeed = 0.00001f; // Very slight bump
void FixedUpdate ()
{
// Every so often, we must prevent jitter
if (Time.time > tickTime)
{
// Apply unnoticeably slight nudge to angular velocity to stop rig jittering bug
Vector3 corr = rig.angularVelocity;
corr.x += tickSpeed;
tickSpeed *= -1; // Apply opposite nudge next time
rig.angularVelocity = corr;
// Reset tickTime
tickTime = Time.time + 59.0f; // Wait another so often
}
}
}
Every 59 seconds I apply a tiny boost to angular velocity. No more jittering… waited 10 minutes and the rig never budged (a noticeable amount… the noise of 0.000001f movements was still there, which over 10 minutes accumulated to a noticeable size, but not over a short period)
What a strange phenomena. I will open a new bug report for this. It is clearly not the same bug as demonstrated with the sphere… I’ll have to work on actual replication steps for it…