I am completely desperate.
How to add torque to 2d sprite? To it`s rigidbody2D.
Let`s say I want to rotate a space ship.
I tried:
rigidbody2D.AddTorque(100);
In every possible way. It just won`t rotate.
AddForce works okay, just not AddTorque.
I am completely desperate.
How to add torque to 2d sprite? To it`s rigidbody2D.
Let`s say I want to rotate a space ship.
I tried:
rigidbody2D.AddTorque(100);
In every possible way. It just won`t rotate.
AddForce works okay, just not AddTorque.
make sure you have successfully acquired a reference to the rigidbody2D before trying to perform physics calculations on it:
private Rigidbody2D rb;
void Start() {
rb = GetComponent<Rigidbody2D> ();
}
my understanding is that rotation occurs only on the z-axis when working in two dimensions. ensure that there is no constraint to the z-axis within the rigidbody2D component attached to the game object in question.
considering there are no constraints to your rigidbody2D, check to ensure that your angular drag is not set too high in relation to the amount of torque you are trying to add when calling the AddTorque function. having too high of an angular drag will require a higher torque to be applied. angular drag is to AddTorque as linear drag is to AddForce.
if these two conditions are satisfied, then there should be no reason why the AddToque function will not work:
void FixedUpdate() {
float horz = Input.GetAxis("Horizontal");
if (horz > 0) { // Right button pressed
rb.AddTorque(horz * 10.0f);
}
}
Lastly, make sure that the torque being applied is defined as a float value as shown in the example above; according to your post, you specified an integer and not a float, and it is very likely that may be your problem as well. always check your console to see if you have any coding errors.