2d arkanoid, we have 1 ball. It is necessary to randomly set its normal and tangential velocity at the beginning. I couldn’t figure out the physics. If you look at the formulas, then the normal velocity is as follows:
float radius = Random.range(0.5f, 3f);
float normalVelocity = Mathf.Pow(rigidbody2d.velocity, 2) / radius
Even if I found the normal and tangential velocity, how do I apply this to the ball in unity?
So far, I’ve only thought of
rigidbody2d.velocity = new Vector2(normalVelocity, tangentialVelocity );
petur
December 21, 2021, 3:38pm
2
rigidbody2d.velocity is just the velocity on each axis
I don’t see the need to get the concepts of tangential and normal velocity involved, since the ball is going to move in a straigth line (right?).
You either need an angle and a single velocity or the velocity in each axis.
Example angle and velocity:
float angle = Random.Range(-45f,45f);
angle = (angle * Mathf.PI) / 180f; // convert degrees to radians
float speed = Random.Range(2f,3f);
float horizontalSpeed = Mathf.Cos(angle) * speed:
float verticalSpeed = Matf.Sin(angle) * speed;
rigidbody2d.velocity = new Vector2( horizontalSpeed, verticalSpeed );