Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Object rotates despite axis is frozen

Discussion in 'Physics' started by noobUs3r, Feb 24, 2021.

  1. noobUs3r

    noobUs3r

    Joined:
    Jan 26, 2021
    Posts:
    3
    I am trying to make a 3D game in Unity. There is an object that has a frozen axis, but the object slowly rotates on this axis. I have a small demonstration video, you can see there that I don't use any scripts (my movement script is disabled) and my Y axis is frozen:


    I will extremely appreciate any help.
     
  2. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    I can replicate this, looks like a bug. I tried dropping a standard cylinder (scale 1, 1, 1) on to an offset step and with the right positioning I could get it to slowly roll down the step, even though it had a y freeze (roll, not slip - transform rotation and angular y velocity on rb).

    If all 3 rotations are frozen it behaves as expected - absolutely zero rotations.

    Switching the Edit -> Project Settings -> Physics -> Solver Type to Temporal Gauss Seidel greatly improved things (no post impact rolling), but a few degrees of rotation were still apparent after the impact.

    It's ugly, but you could run a FixedUpdate script to reset the desired rotation. Or play with the physics settings a bit more to see if you can get something that is "good enough".
     
  3. noobUs3r

    noobUs3r

    Joined:
    Jan 26, 2021
    Posts:
    3
    Thank you very much for your reply! I have tried the workaround you suggested but my object moves very strange with it:
    private void Update()
    {
    transform.rotation = Quaternion.Euler(-90, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
    }

    I will submit this behavior as a bug and will see how it goes. Will let you know.

    Best Regards,
    noobUs3r
     
  4. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    If you move a rigidbody like this (transform.rotation), then you are effectively teleporting it - the rotation is in no way controlled by the physics engine or constrained by the Freeze options.

    If you have a kinematic rigidbody, you should be using Rigidbody.MovePosition / Rigidbody.MoveRotation

    If you have a non-kinematic rigidbody (as I believe you have and which I tested), you should be moving it with Rigidbody.Add[Force/Torque etc] or allowing to freely move under external forces, check the public methods here https://docs.unity3d.com/ScriptReference/Rigidbody.html

    When you do move/apply force to a rigidbody, you will nearly always want to do it in FixedUpdate (physics step) and not in Update (frame render step), be aware of this: https://docs.unity3d.com/Manual/ExecutionOrder.html although, IMHO it is not perfectly correct in all that it implies, it is a good visual of what is going on.
     
  5. noobUs3r

    noobUs3r

    Joined:
    Jan 26, 2021
    Posts:
    3
    So this is a response from the support team:
    upload_2021-3-2_1-13-13.png

    Doesn't really make sense to me to be honest...
     
  6. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    Not the best response really. Going back to the replicator I made for the dropped cylinder, all I can say is that switching to Temporal Gauss Seidel helped, but still left a small rotation from the initial collision - perhaps this is regarded as an acceptable compromise for the simplicity of using infinite inertias to control degrees of freedom.
     
  7. FahmyEldeeb

    FahmyEldeeb

    Joined:
    May 11, 2021
    Posts:
    3
    it causes issues, I have rigidbodies with a script to move them forward and nothing else, but they start accumilating Y rotation, I'm guessing because of friction with the ground and soon their forward is no longer correct.