pausing messing up bullet acceleration

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
pgimeno
Party member
Posts: 3683
Joined: Sun Oct 18, 2015 2:58 pm

Re: pausing messing up bullet acceleration

Post by pgimeno »

It seems you misunderstood. You need two acceleration variables in the bullet, one per axis. You need to initialize them to the sine and cosine of the angle times the desired acceleration (which varies with the pattern), similarly to how you're initializing the velocity dx and dy with the sine and cosine of the angle times the bullet speed. In one of the patterns, you had a starting velocity (0.6); you'll need to add that to the bullet's initial velocity.

Then in the movement routine, you need to apply the acceleration to the speed, the way I've explained above.

Increasing the velocity by 488 or 1000 every frame makes no sense; luckily you were not doing it at all yet, but you'll need to change the values to make it work. It appears that you were using 1/3 and 1 pixels/s per second, depending on the pattern.
ITISITHEBKID
Prole
Posts: 18
Joined: Tue Apr 24, 2018 7:37 pm

Re: pausing messing up bullet acceleration

Post by ITISITHEBKID »

pgimeno wrote: Tue May 29, 2018 9:28 am It seems you misunderstood. You need two acceleration variables in the bullet, one per axis. You need to initialize them to the sine and cosine of the angle times the desired acceleration (which varies with the pattern), similarly to how you're initializing the velocity dx and dy with the sine and cosine of the angle times the bullet speed. In one of the patterns, you had a starting velocity (0.6); you'll need to add that to the bullet's initial velocity.

Then in the movement routine, you need to apply the acceleration to the speed, the way I've explained above.

Increasing the velocity by 488 or 1000 every frame makes no sense; luckily you were not doing it at all yet, but you'll need to change the values to make it work. It appears that you were using 1/3 and 1 pixels/s per second, depending on the pattern.
Thanks for all your help, but this is absolutely driving me up the wall. I tried my best to implement what you said but it still dosen't work and the game now lags terribly when there are just a few bullets on screen. I was considering going back, but at this point it would probably be more effort then just finishing it. Thanks again for all of your help, you've been lovely so far.
Attachments
changedagain.love
(1.18 MiB) Downloaded 61 times
User avatar
pgimeno
Party member
Posts: 3683
Joined: Sun Oct 18, 2015 2:58 pm

Re: pausing messing up bullet acceleration

Post by pgimeno »

The lagging may be due to having 3 prints per bullet per frame. That's a lot of output to the terminal, and output to the terminal is slow.

Here's what I suggested, more explicitly:

- In spawnbullet, use this:

Code: Select all

-- calculate a direction vector
local dirx = math.cos(angle)
local diry = math.sin(angle)
-- variables for velocity and acceleration
local velx, vely, accx, accy

if pattern == 1 then
  -- 60% speed at start, accel 1/3 px/s/s
  velx = 0.6 * bulletspeed * dirx
  vely = 0.6 * bulletspeed * diry
  accx = 1/3 * dirx
  accy = 1/3 * diry
elseif pattern == 2 then
  numbull = 2
  space = 0.12
  -- full speed at start, accel 1 px/s/s
  velx = bulletspeed * dirx
  vely = bulletspeed * diry
  accx = 1 * dirx
  accy = 1 * diry
elseif pattern == 3 then
  -- no speed or acceleration
  velx = 0
  vely = 0
  accx = 0
  accy = 0
end

timer:every(space, function()
  bullets[#bullets+1]={
    x = fx,
    y = fy,
    r = fr,
    dx = velx,
    dy = vely,
    ax = accx, -- store the acceleration in the bullet too
    ay = accy,
    btype = type,
    creation_time = love.timer.getTime(),
    pattern = pattern,
  }
end,numbull)
- In love.update, use this:

Code: Select all

for i=#bullets,1,-1 do
  if gamestate == "playing" then
    b = bullets[i]
    -- update velocity
    b.dx = b.dx + b.ax * dt
    b.dy = b.dy + b.ay * dt
    -- update position
    b.x = b.x + b.dx * dt
    b.y = b.y + b.dy * dt
  end
end
ITISITHEBKID
Prole
Posts: 18
Joined: Tue Apr 24, 2018 7:37 pm

Re: pausing messing up bullet acceleration

Post by ITISITHEBKID »

pgimeno wrote: Thu May 31, 2018 1:47 am The lagging may be due to having 3 prints per bullet per frame. That's a lot of output to the terminal, and output to the terminal is slow.

Here's what I suggested, more explicitly:

- In spawnbullet, use this:

Code: Select all

-- calculate a direction vector
local dirx = math.cos(angle)
local diry = math.sin(angle)
-- variables for velocity and acceleration
local velx, vely, accx, accy

if pattern == 1 then
  -- 60% speed at start, accel 1/3 px/s/s
  velx = 0.6 * bulletspeed * dirx
  vely = 0.6 * bulletspeed * diry
  accx = 1/3 * dirx
  accy = 1/3 * diry
elseif pattern == 2 then
  numbull = 2
  space = 0.12
  -- full speed at start, accel 1 px/s/s
  velx = bulletspeed * dirx
  vely = bulletspeed * diry
  accx = 1 * dirx
  accy = 1 * diry
elseif pattern == 3 then
  -- no speed or acceleration
  velx = 0
  vely = 0
  accx = 0
  accy = 0
end

timer:every(space, function()
  bullets[#bullets+1]={
    x = fx,
    y = fy,
    r = fr,
    dx = velx,
    dy = vely,
    ax = accx, -- store the acceleration in the bullet too
    ay = accy,
    btype = type,
    creation_time = love.timer.getTime(),
    pattern = pattern,
  }
end,numbull)
- In love.update, use this:

Code: Select all

for i=#bullets,1,-1 do
  if gamestate == "playing" then
    b = bullets[i]
    -- update velocity
    b.dx = b.dx + b.ax * dt
    b.dy = b.dy + b.ay * dt
    -- update position
    b.x = b.x + b.dx * dt
    b.y = b.y + b.dy * dt
  end
end
Thank you so much, and sorry for being so confused before! Fixed my problem perfectly :nyu:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests