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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Problem Accessing Rigidbody.maxAngularVelocity

Discussion in 'Physics' started by madderfizban, Jul 2, 2016.

  1. madderfizban

    madderfizban

    Joined:
    Jul 2, 2016
    Posts:
    2
    Hi guys, since Unity updated to V5 the maxAngularVelocity option has been removed from the physics menu and the wiki only has this information:

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Description
    The maximimum angular velocity of the rigidbody. (Default 7) range { 0, infinity }.

    The angular velocity of rigidbodies is clamped to maxAngularVelocity to avoid numerical instability with fast rotating bodies. Because this may prevent intentional fast rotations on objects such as wheels, you can override this value per per rigidbody.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Is there still an easy way to access this that I missed and cannot find? There is no way to access it from the ridbody in the inspector.

    Sorry if this comes off as a noob question, I am still a begginer :)
     
  2. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    356
    Yes, it's accessible through code...
    Code (CSharp):
    1. GetComponent<Rigidbody>().maxAngularVelocity = 7f;
     
  3. madderfizban

    madderfizban

    Joined:
    Jul 2, 2016
    Posts:
    2
    Awesome, works perfectly. Thanks!
     
  4. henningm

    henningm

    Joined:
    Jul 11, 2016
    Posts:
    18
    I hope I can ask you a question about rigidbody, I see you helped other about it. Am using unity 5.3.5f1 personal.

    This is the old rigidbody code: rigidbody.velocity.y = jumpheight; and I can't use it in 5.3.


    script start.

    #pragma strict
    var rotationSpeed = 50;
    var jumpHeight = 8;
    private var isFalling = false;

    function Update ()
    {
    // handle ball rotation var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
    rotation *= Time.deltaTime;
    rigidbody.AddRelativeTorque (Vector3.back * rotation);
    if GetKeyDown (KeyCode.W) && isFalling == false);
    {
    rigidbody.velocity.y = jumpHeight;
    }
    isFalling = true;
    }
    function OnCollisionStay ()
    {
    isFalling = false;
    }

    script end.


    I know this is old but I hope someone can help me out. This is the code I try to work but is failing.
    script start.

    #pragma strict
    var rotationSpeed = 50;
    var jumpHeight = 8;
    private var isFalling = false;

    function Update ()
    {
    // handle ball rotation var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
    rotation *= Time.deltaTime;
    GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);
    if (Input.GetKeyDown (KeyCode.W) && isFalling == false );
    {
    GetComponent.<Rigidbody>().velocity.y = jumpHeight;
    }
    isFalling = true;
    }
    function OnCollisionStay ()
    {
    isFalling = false;
    }

    script end.

    Am using 5.3 unity. I guess rigidbody code is different in 5.3 than the old one. Now the ball is jumping without me touching the key.
     
  5. memBrain

    memBrain

    Joined:
    Aug 1, 2012
    Posts:
    7
    First of all, calling rigidbody like that is deprecated. You shouldn't use it. Instead you should declare your own Rigidbody:

    var rb = gameObject.GetComponent<RigidBody>(); // See quote below:

    Also, you cannot assign directly to rb.velocity.y. to set this value you'd want to do:

    rb.velocity = new Vector3(rb.velocity.x, jumpHeight, rb.velocity.z); [Edit: you can set any value for x and z; I chose these values to preserve whatever was already stored in velocity.]

    That should fix your Rigidbody issues.