Page 1 of 1

[Solved]Need a little bump help

Posted: Sun Feb 10, 2019 5:03 pm
by H0lyT0ast
Hi Everyone,

Thank you for taking the time to read my issue.

So i dont really understand bump that well and I seem to be at an impass. I've looked over the bump tutorial over and over. I dont seem to be understanding 2 key aspects.

1. adding, non-player, object to the word
2. moving said object



I think my issue exists in these two statements.

adding non player to the world:

Im not sure if im adding the object correctly in this statement. If I change the world:add to something else the game fails

Code: Select all

if love.keyboard.isDown('space') and canshoot then
		newBullet = {style = 'line',x=player.x+(player.width/2), y = player.y,width = bullets.width,segments = bullets.segments }
		world:add(newBullet, newBullet.x,newBullet.y, newBullet.width, newBullet.segments)
	table.insert(bullets,newBullet)
	  canshoot = false
		canshootTimer = canshootTimerMax
		bulletCount = bulletCount + 1
	end
Moving the bullet: I think im moving correctly, but when I added some collision detection nothing happened.

Code: Select all

	for i, bullet in ipairs(bullets) do
		bullet.y = bullet.y - (250 * dt)
		world:move(newBullet, 0,newBullet.y - (250*dt))
		if bullet.y < 0   then
		table.remove(bullets,i)
		bulletCount = bulletCount - 1
		end
	end


If someone could help me out, I would really appriciate it. I really like Love2d but im just new and dont see my issue yet.

Re: Need a little bump help

Posted: Sun Feb 10, 2019 6:16 pm
by pgimeno
Not sure what you expected to happen, but you don't do anything with the return values of world:move(), which are crucial in bump.

To start with, modify your world:move line as follows:

Code: Select all

bullet.x, bullet.y, collisions = world:move(bullet, bullet.x, bullet.y)
Now, your bullet spawns right at the player. Making it spawn a bit above the player makes it not hit the player, and you don't need to mess with filters. Otherwise you would need to check what the bullet collided with, and ignore the collision when it's with the player.

Once that's fixed, you can just check if #collisions == 0 and if not, remove the bullet, as that means it hit something.

Re: Need a little bump help

Posted: Sun Feb 10, 2019 8:16 pm
by H0lyT0ast
Thank you, I got it working now.

I was under the impression that when calling the world:move() it needed to be the table name i added. so in this case i was erroneously moving newBullet causing a heap of trouble.

Thanks for clarifying.