- Home /
Maximum angular velocity
Hi, I'm working on making an object swing around a pivot in a 2D project with speeds based on mouse input. Everything is working fine, I just can't set the maximum angular velocity. I've tried clamping, I've tried if angularVelocity > max set angularVelocity, I've tried setting angular velocity instead of adding torque, I tried changing physics settings, I've even tried adding opposite direction torque. Every time I can get it swinging too fast, or when I tried to take torque out of it and set angular velocity directly it didn't move. Here is my current code for this part. Any help would be greatly appreciated!
if (Input.GetMouseButton(0)) {
rb2d.freezeRotation = false;
mouseMove = -Input.GetAxis ("Mouse X")/22f;
//rb2d.angularVelocity += mouseMove;
rb2d.AddTorque (mouseMove, ForceMode2D.Force);
rb2d.angularVelocity = Mathf.Clamp (rb2d.angularVelocity, -maxRot, maxRot);
}
Comment