Hi all,
Been watching some tutorials and trying out this classic pong game and I stuck at this place where the ball is supposed to gain speed as it collides on the bat. However, the code isn’t working (though there are no errors).
So what I have done is written the function to gain speed as the ball hits the bat and its after the update code block. The script is component of the Bat gameOBJ
I have declared a variable ballCollisionSpeed to be equal to 5.
void onCollisionExit2D(Collision2D ballTouch)
{
ballTouch.rigidbody.velocity = new Vector2( ballTouch.rigidbody.velocity.x * 2.1f, ( ballTouch.rigidbody.velocity.y + ballCollisonSpeed) * Time.deltaTime);
Debug.Log(ballTouch.rigidbody.velocity);
Debug.Log("COLLIDED");
print("I have collided");
}
The ball not only slows down after gradually (opposite of what I want), but none of Debug.Log shows up on the console, nor does the print. I tried re-arranging the code, setting it up in the ball gameOBJ but nothing seems to work. It’s as if the code is not being read at all. As I commented out the code and the game doesn’t seem to be affected.
Thanks for help & regards.
-G