Reputation: 3299
I have a rigidbody2d in my unity project with circleCollider attached. When the game starts, user can press left and right arrows to speed up or slow down the ball. But once when the ball comes to rest, even after applying huge amounts of torque, the ball is not starting to move.
The rigidbody2d values are as follows:
Mass 1, Linear drag 0.1, Angular drag 0.05, Gravity scale 1
The physics material2d values of floor are as follows:
Friction 0.4, Bounciness 0.5
I use this line to add torque:
float torque = Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime;
ballRigidBody2D.AddTorque(torque);
The torque value getting here is around 10000 - 100000
Edit: Just now I noticed in scene view that, whenever I press left or right arrow, it suddenly rotates through an angle and then stops. When I release the key though, it starts to spin fast for few seconds like a top and then eventually comes to rest. (but it doesn't move an inch while doing all these circus.)
Upvotes: 0
Views: 238
Reputation: 1248
The first thing you need to understand is that AddTorque add a rotational force and since it is a force you need the components of it so:
float torque = Input.GetAxis("Horizontal");
ballRigidBody.AddTorque (torque * rotationSpeed * Time.deltaTime);
Multiply the torque inside the AddTorque in order to make it work fine.
Then add your torque in the Fixed update that works better with physics. Try also to add a material with zero friction to the ball that maybe can cause some problems.
Make sure to have a collider on ball and floor and 2 rigidbodies
Upvotes: 0