I'm doing a Pong game, and I got the bounce from the ball when it collides with the paddles.
But, as far I know, the angle which the ball enters and collides with the paddle is the same from the "exit", so the game now is a bit predictable and boring, especially if the game starts the ball with 0 degrees, it goes on horizontally forever between the paddles.
I want to add a little "randomness" to this exit angle when the ball hits the paddle, but I have no idea how to do it. I know it has something to do with the normal vector and the random functions godot has, but I have absolutely no idea how to implement and code it.
This is my code right now:
export var speed = 500
var velocity = Vector2.ZERO
func _ready() -> void:
velocity.x = [-1,1][randi() % 2]
velocity.y = [-0.7,0.7][randi() % 2]
func _physics_process(delta: float) -> void:
var collision = move_and_collide(velocity * speed * delta)
velocity = velocity.bounce(collision.normal)