im making a simple pong clone in unity using the 2d tools provided. I have it up and running with the ball x velocity switching when it hits a player, and the y velocity switching when it hits a wall:
void OnCollisionEnter2D(Collision2D collision) {
// Invert the velocity
if (collision.gameObject.name == "Player")
{
if (speed > 0)
{
speed++;
}
else
{
speed--;
}
speed = speed * -1;
rigidbody2D.velocity = new Vector2 (speed, UpDown);
print ("i hit player");
}
theres a couple of extra lines in there, which increase the ball speed on every hit and also print a debug message onto the console. Any tips on modifying it so that the area of the player paddle that is hit will affect the UpDown(y axis) of the ball?