I'm working on a billiard game in Unity (2D), where I used 3D sphere visually and I'm trying to make the ball's rotation look natural as it moves across the table or hit another. I've got the ball moving using Rigidbody2D, but the rotation doesn't quite look right, especially when the ball changes direction or hits a cushion. Sometimes, the rotation seems off, and I want it to feel more natural.
If you could look up this video it just sometimes has weird rotaiton around it self and seems odd i just want to look more like realistic rotation of normal sphere.
public class BilliardBallRotation : MonoBehaviour
{
private Transform ball3D;
public float ballRadius = 0.5f;
public float rotationSpeed = 1.0f;
private float circumference;
private Rigidbody2D rb;
private float angle;
void Start()
{
rb = GetComponent<Rigidbody2D>();
circumference = 2 * Mathf.PI * ballRadius;
sphere3D = transform;
}
void Update()
{
if (rb != null && rb.velocity != Vector2.zero)
{
float distanceMoved = rb.velocity.magnitude * Time.deltaTime;
angle = (distanceMoved / circumference) * 360 * rotationSpeed;
sphere3D.Rotate(Vector3.forward, -angle, Space.Self);
}
}
}