Hi!
I noticed that in arkanoids when the ball and the paddle collides the ball goes in a direction based on its position to the paddle. So if the ball hits the paddle on the left it goes left, on right it goes right and the further the ball is from the midpoint the more it goes sideways. I came up wtih a way to make this behaviour. See the code here:
if(collision.collider.CompareTag("Player"))
{
float ballLocationX = transform.position.x;
float paddleLocationX = collision.collider.transform.position.x;
float difference = ballLocationX - paddleLocationX;
myRigidBody2D.velocity = new Vector2(difference * tweakOnPaddleCollision, yPush);
}
The only problem with this is i think by standard arkanoid rules (which i’m trying to keep my game to) the ball should have a constant speed except for when powerups are used. But the more the ball is on the side compared to the paddle, the faster it is, i guess because y and x velocity kinda’ adds together. How could i possibly solve this so the ball goes in a direction based on the collision point and keeps a constant speed? Thank you for your answers in advance!