but the ball gets ridiculously fast very quickly.
I can reproduce this if I try to hit the ball against the wall at a very low angle (i.e. almost aligned with the wall) which I always try because I want to get the ball up and behind the brick (quickest way to win arkanoid, I believe). So I go up to the side wall and try to get the ball past the bricks, which makes the ball hit the wall at the low angle and it speeds up very fast.
I've made the speed growth slower.
The updated love-file is attached.
Part of the problem was in Ball:increase_speed_after_collision() function.
The speed was increasing each 5 collisions and the growth rate was exponential:
Code: Select all
function Ball:increase_speed_after_collision()
if self.collision_counter % 5 == 0 then
self.speed = self.speed * self.collision_speed_multiplier
end
end
I've updated this function so that the speed increases each 10 collisions and changed the growth rate to linear:
Code: Select all
function Ball:increase_speed_after_collision()
local speed_increase = 20
if self.collision_counter % 10 == 0 then
self.speed = self.speed + self.speed:normalized() * speed_increase
end
end
So I go up to the side wall and try to get the ball past the bricks, which makes the ball hit the wall at the low angle and it speeds up very fast. It looks like a calculation error with the reflecting of the ball? A reflection shouldn't change the velocity, only the direction...?
Sometimes, due to some error in collision resolution, the ball hits the wall several times repeatedly.
This causes rapid growth of the ball's speed.
I'm not sure what exactly the problem is, so I haven't fixed it yet.
As a quick fix I can suggest to comment out the lines
self:increase_collision_counter() and self:increase_speed_after_collision() in the
Ball:react_on_wall_collision function inside the Ball.lua:
Code: Select all
function Ball:react_on_wall_collision( another_shape, separating_vector )
self.position = self.position + separating_vector
self.collider_shape:moveTo( self.position:unpack() )
self:normal_rebound( separating_vector )
self:min_angle_rebound()
--self:increase_collision_counter()
--self:increase_speed_after_collision()
ball_wall_sound:play()
end
This way, the ball will not get any speed increase after collisions with the walls.