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

rigidbody2D.AddToruqe not working

Discussion in 'Editor & General Support' started by Wrymnn, Sep 29, 2014.

  1. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    352
    I went with this to Unity Answers, nobody knew the problem so I`m coming here.

    Hello I have this C# script attached to player in Fixed Update:
    Code (csharp):
    1.  
    2.     rigidbody2D.AddTorque(Input.GetAxis ("Horizontal") * 5f);
    3.  
    It just won`t work. AddForce works and everything else in that script just not this.

    What I have tried so far:
    Code (csharp):
    1.  
    2.     if(Input.GetButton("Horizontal"))
    3.          rigidbody2D.AddTorque(5f);
    4.  
    Even this won`t work in Update without any key check:
    Code (csharp):
    1.  
    2.     rigidbody2D.AddTorque(5f);
    3.  
    Yes the script is attached, Yes object has Rigidbody2D. As I said, AddForce works, just torque not.
    Is Kinematic and Fixed angle are Checked OFF.

    Please help I am getting hopeless.



    EDIT, FOUND A BUG:

    the problem was it could not be like that:
    Code (csharp):
    1.  
    2. public float rotationSpeed;    //This was set in inspector as 10 lets say
    3.  
    4. function FixedUpdate()
    5. {
    6.          rigidbody2D.AddToruq(Input.GetAxis("Horizontal") * rotationSpeed);
    7. }
    8.  
    It has to be not defined in inspector, but inside code.

    Code (csharp):
    1.  
    2. public float rotationSpeed = 10f;    //This will now work.
    3.  
    4. function FixedUpdate()
    5. {
    6.          rigidbody2D.AddToruq(Input.GetAxis("Horizontal") * rotationSpeed);
    7. }
    8.  
    I guess it is bug.
     
    Last edited: Sep 30, 2014
  2. Josh-Naylor

    Josh-Naylor

    Administrator

    Joined:
    Jul 1, 2014
    Posts:
    216
    What happens when you are in play-mode and un-tick Kinematic?
     
  3. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    352
    It is unticked. I never ticked it.

    the problem was it could not be like that:
    Code (csharp):
    1.  
    2. public float rotationSpeed;    //This was set in inspector as 10 lets say
    3.  
    4. function FixedUpdate()
    5. {
    6.          rigidbody2D.AddToruq(Input.GetAxis("Horizontal") * rotationSpeed);
    7. }
    8.  
    It has to be not defined in inspector, but inside code.

    Code (csharp):
    1.  
    2. public float rotationSpeed = 10f;    //This will now work.
    3.  
    4. function FixedUpdate()
    5. {
    6.          rigidbody2D.AddToruq(Input.GetAxis("Horizontal") * rotationSpeed);
    7. }
    8.  
    I guess it is bug.
     
  4. Josh-Naylor

    Josh-Naylor

    Administrator

    Joined:
    Jul 1, 2014
    Posts:
    216
    I know that but can you press play, tick it then un-tick it and see what it does, It's not working for me but for some reason does when I do this.
     
  5. Josh-Naylor

    Josh-Naylor

    Administrator

    Joined:
    Jul 1, 2014
    Posts:
    216
    For some reason when you apply any 2d collider onto the object the AddTorque works fine as expected, can you submit a bug report with a project and for the time being add a 2d collider to the object you are trying to effect.
     
    Wrymnn likes this.
  6. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    352
    Okay hope I fond time for it :) Yes I already applied collider.