[Solved]Need a little bump help

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.
Post Reply
User avatar
H0lyT0ast
Prole
Posts: 7
Joined: Sun Feb 03, 2019 5:44 pm

[Solved]Need a little bump help

Post 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.
Attachments
main.lua
(2.05 KiB) Downloaded 189 times
Last edited by H0lyT0ast on Sun Feb 10, 2019 8:18 pm, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Need a little bump help

Post 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.
User avatar
H0lyT0ast
Prole
Posts: 7
Joined: Sun Feb 03, 2019 5:44 pm

Re: Need a little bump help

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 0 guests