In my endless runner game, my player object is not moving at all, I move all the other game objects.
The way I move them is by something like this, with speed being increased every 5 secs.
local speed = 1
local function increaseSpeed()
speed = speed * 1.1
end
-- moving background objects on every frame
local function update()
for i = #backgrounds, 1, -1 do
local b = backgrounds[i]
b:translate(-(speed * 3), 0)
end
end
Runtime:addEventListener("enterFrame", update)
speedIncreaseTimer = timer.performWithDelay(5000, increaseSpeed, 0)
And my hero is just jumping over the blocks with a linear impulse like this
function hero:jumpNow()
self:jumpAnimation()
self:applyLinearImpulse(0, -8*self.mass, self.x, self.y )
end
The problem I am facing is as the game speed increases to a considerable amount, the player jumps are getting longer and longer, as expected because the blocks are coming with a higher speed.
I have 2 questions on this whole setup if someone could shed some light on -
-
How do I setup a correlation between my game speed and linear impulse so the jump feel more natural as the game progresses ?
-
Is my increasing the same speed increase mechanism right way to achieve something like this, or there are other options which I should look into ?
Thank you,