Hello,
I have been puzzling over this problem for a while now and really cannot see my problem. I hope someone can help. As far as I understand my ball should maintain its velocity throughout the level, and once the random.range tweak is inserted should in fact gradually speed up. However my ball slows down before the random.range is put in and after. I also experience ‘boring loops’ even with the random.range.
The random.range change is definetly logging in the console withe ach collision.
I have checked the physics2DSettings (gravity set to -1 in y).
I have played around with the velocity setting and tweak settings and although this has teh expected effect insofar as changes ball direction and initial speed it still always slows down.
This is the script I have for the ball;
void Update () {
if (!hasStarted) {
//Lock Ball position to paddle
this.transform.position = paddle.transform.position + paddleToBallVector;
//Wait for mouse button to launch
if (Input.GetMouseButtonDown(0)) {
print ("Mouse clicked");
hasStarted = true;
this.rigidbody2D.velocity = new Vector2 (2f, 20f);
}
}
}
void OnCollisionEnter2D (Collision2D collision){
Vector2 tweak = new Vector2 (Random.Range (0f, 0.2f), Random.Range (0f, 0.2f));
print (tweak);
rigidbody2D.velocity += tweak;
}
}
Any thought?
Many thanks