Hi,
I m making a simple ball breaker game and I use the code below to handle ball launch and collisions . Whole procedure uses Vector2 for launch and for angle change as well. My goal is to speed up ball by time. I know I can use coroutines but my issue is how to handle speed when movement is made with vector2 .
Ball scripts contains bellow code ;
Launch Ball
public void ShootCannonsOnClick()
{
if (Input.GetMouseButtonDown(0))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(XLanch, YLanch);
//Myrigidbody2D.velocity = transform.forward * BallSpeed;
GameStarted = true;
}
}
Change Angle when collide;
private void OnCollisionEnter2D(Collision2D collision)
{
Vector2 velocityTweek = new Vector2(UnityEngine.Random.Range(0.0f, randomFactor), UnityEngine.Random.Range(0.0f, randomFactor));
if (GameStarted)
{
AudioClip clip = Ballsounds[UnityEngine.Random.Range(0, Ballsounds.Length)];
MyAudioSource.PlayOneShot(clip);
Myrigidbody2D.velocity = Myrigidbody2D.velocity + velocityTweek;
}
}