Pausing in my game messes up bullet acceleration. I know why, but I'm not sure how to fix it. It is happening because I calculate acceleration by using the formula (love.timer.getTime() - bullets creation time), but while the game is paused, love.Timer.getTime is still increasing, leading to bullets zooming away as soon as the game is unpaused. What can I do about this problem? I am using love 11.0. Included are useful code snippets and the .love file for my game.
for i=#bullets,1,-1 do
b = bullets[i]
local timedif = love.timer.getTime() - b.creation_time
if gamestate == "playing" then
b.x = math.round(b.x + (b.dx * dt)* (timedif/3+0.6))
b.y = math.round(b.y + (b.dy * dt)* (timedif/3+0.6))
end
end
Note: when running the .love file you can use f1 to spawn more enemies
You could try passing dt from love.update into your bullet acceleration code through the code path, and in that case, you'd just need to edit love.update to include something like this:
function love.update(dt)
if gamestate == 'paused' then return end
-- do normal processing
updateBullets()
-- ...etc.
end
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
zorg wrote: ↑Mon May 28, 2018 10:56 pm
You could try passing dt from love.update into your bullet acceleration code through the code path, and in that case, you'd just need to edit love.update to include something like this:
Using love.timer.getTime() is a weird way to go about this. But if you really want to do it that way, you could subtract the total pause time from the time, to compensate (untested):
local pauseTime
local totalPauseTime = 0
function love.keypressed(key)
if key == "escape" then
if gamestate == "paused" then
gamestate = "playing"
totalPauseTime = totalPauseTime + (love.timer.getTime() - pauseTime)
else
gamestate = "paused"
pauseTime = love.timer.getTime()
end
end
end
...
for i=#bullets,1,-1 do
b = bullets[i]
local timedif = love.timer.getTime() - totalPauseTime - b.creation_time
if gamestate == "playing" then
b.x = math.round(b.x + (b.dx * dt)* (timedif/3+0.6))
b.y = math.round(b.y + (b.dy * dt)* (timedif/3+0.6))
end
end
pgimeno wrote: ↑Tue May 29, 2018 12:37 am
Using love.timer.getTime() is a weird way to go about this. But if you really want to do it that way, you could subtract the total pause time from the time, to compensate (untested):
I only used love.timer.getTime() because it's what I thought of. A better way to do it would be great!
ITISITHEBKID wrote: ↑Mon May 28, 2018 11:33 pm
This did not work for me, as love.timer.getTime() still increases
Of course it does.
Apologies, it seems i missed the most important statement in my previous post;
Instead of using love.timer.getTime, You could try passing dt from love.update into your bullet acceleration code through the code path, and in that case, you'd just need to edit love.update to include something like this: <Code from my previous post>
Because the dt parameter in love.update is basically the same value you get from love.timer.getTime; if you don't call update code there, nothing will change, which is what you want... more or less.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
I have taken a look at the full code and I'm finding it difficult to understand what you're trying to do with the different patterns. At first sight it appears that it's intended to apply an acceleration to the bullets, as if they were missiles. Is that it?
If so, the simplest way to apply acceleration is to add the acceleration times dt to the velocity. Something of this kind (which is just schematic, not adapted to your code):
vx = vx + ax * dt
vy = vy + ay * dt
x = x + vx * dt
y = y + vy * dt
To adapt that to your code, you probably need to add a current acceleration variable in the bullets, which should have the same direction (cos/sin) times an acceleration that depends on the pattern.
pgimeno wrote: ↑Tue May 29, 2018 1:00 am
I have taken a look at the full code and I'm finding it difficult to understand what you're trying to do with the different patterns. At first sight it appears that it's intended to apply an acceleration to the bullets, as if they were missiles. Is that it?
Yes, bullets have acceleration. I am implementing your changes now.