What I am trying to do is make a ball in a brick breaker game stop sticking on the vertical and horizontal axis. I want to execute this by adding to the balls velocity whenever it is between a speed of -1 and 1 by using adding a random range of velocity between -0.5 and 0.5.
How would I actually reference the ball and execute this in an if else statement?
I’ve tried several ways, but I’m too new to c# and unity to grasp the proper syntax or formula still.
I’m thinking from researching that I need to reference the rigidbody of the ball. I have the idea of what I want to accomplish in my head, but I’m not sure how to write it out. Would it be something like this? I’m not sure if I used too many if statement or used them incorrectly, but I’m hoping this is close to the solution.
private void OnCollisionEnter2D(Collision2D collision)
{
If (Theball >= 1f ) {
transform.Translate(vector2.right * Time.deltaTime);
}
If (Theball <= -1f) {
transform.Translate(vector2.left * Time.deltaTime);
}
TheBall = get component<Rigidbody2D.velocity.x>()
}
If (Theball >= 1f ) {
transform.Translate(vector2.up * Time.deltaTime);
}
If (Theball <= -1f) {
transform.Translate(vector2.down * Time.deltaTime);
}
TheBall = get component<Rigidbody2D.velocity.y>()
}
}