As I mentioned in a different thread, that's actually not LERPing (linear interpolation); that's an exponential approach (a geometric succession) with an asymptote in the target position, meaning it will approximate it more and more and more but never go past it. It's not how you're supposed to use the lerp function usually.
Your approach isn't the most adequate for a bouncing ball. Rather than setting targets, you should set velocities. It's not that hard. Basically, the velocity is the amount of pixels in each axis that the ball travels each second. So, every frame you add the velocity times the frame time (dt) to the position, and that's all.
Bouncing consists of changing the sign of one of the velocity axes.
Something like this (note: you need to keep your brain engaged to use it)
Code: Select all
-- Initialize the position in some way
ball.x = ...
ball.y = ...
-- Initialize the velocity in some way, for example a fixed speed at a random direction
local speed = 20 -- that's 20 pixels per second
do
local angle = 2*math.pi*love.math.random() -- choose a random direction
ball.vx = cos(angle) * speed
ball.vy = sin(angle) * speed
end
-- Do something like this when you need to update
ball.x = ball.x + ball.vx * dt
ball.y = ball.y + ball.vy * dt
-- Do something like this when you detect bouncing on a horizontal wall
ball.vy = -ball.vy
-- Do something like this when you detect bouncing on a vertical wall
ball.vx = -ball.vx
You will typically also need to correct the position of the ball when it bounces, because when you detect the collision, it's already past the wall. That's called collision resolution. If you have trouble with that, maybe you could use a library that handles it.
Edited to fix typo