Wrymnn
September 28, 2014, 9:34am
1
Hello I have this C# script attached to player in Fixed Update:
rigidbody2D.AddTorque(Input.GetAxis ("Horizontal") * 5f);
It just won`t work. AddForce works and everything else in that script just not this.
What I have tried so far:
if(Input.GetButton("Horizontal"))
rigidbody2D.AddTorque(5f);
Even this won`t work in Update without any key check:
rigidbody2D.AddTorque(5f);
Yes 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.
Wrymnn
October 6, 2014, 1:35pm
3
THE SOLUTION:
2D addTorque is bugged.
When you do this:
public float rotationSpeed; //And now you assaign it in inspector
void FixedUpdate()
{
rigidbody2D.AddTorque(Input.GetAxis ("Horizontal") * rotationSpeed);
}
It wont work. Because it
s bugged. But when you don`t assaign it in the inspector, it works fine.
void FixedUpdate()
{
float rotationSpeed = 5.0f;
rigidbody2D.AddTorque(Input.GetAxis ("Horizontal") * rotationSpeed);
}
This works. At least for me.
Maybe the value calculated with " Input.GetAxis (“Horizontal”) * 5f " is too small for the mass of the object, try a very large one.
Also call WakeUp after adding the torque: