help with collisions

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
bobbymcbobface
Citizen
Posts: 50
Joined: Tue Jun 04, 2019 8:31 pm

Re: help with collisions

Post by bobbymcbobface » Sun Sep 22, 2019 8:05 am

ok i tried returning the values of world:move and it kind of works though there's one problem

(here's my love file)
game.love
(7.16 MiB) Downloaded 28 times
this section of code:

Code: Select all

  for i=1,len do
    local other_ = cols[i].other
    if other_.isCoin then
      print('coin')
    elseif other_.isExit then
      print('exit')
    elseif other_.isSpring then
      print('spring')
    end
    print('collided with ' .. tostring(cols[i].other))
  end
specifically this line:

Code: Select all

print('collided with ' .. tostring(cols[i].other))
only returns two collsion tables:
collided with table: 0x0d82b440
collided with table: 0x0d820738
which I'm guessing is where i spawn in; what i need is for this to continually loop but not interrupt the rest of the code

can you help?

-thanks
I make games that run on potatoes :P

User avatar
pgimeno
Party member
Posts: 1870
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

Re: help with collisions

Post by pgimeno » Sun Sep 22, 2019 11:22 am

You have two calls to world:move. The first call (on line 33 of sprite.lua in the version you've attached) has dx=0 dy=0 because it is placed before checking the keys. Therefore the goal will always be the current player position, producing no movement, and no collision will happen.

Remove the first call and use the second one to check for collisions.

You have no isExit, isSpring etc. in the objects, so it makes no sense to check those. You only have x and y. If you want to add more attributes, do so in lobby.lua, in the table you add with sprite:add_collision({...},...) because whatever you add there, you will get it back in the collisions. For example, sprite:add_collision({type=character}, ...) will store the map character in the collision, and then when checking for collisions, you'll find that cols[i].other.type is the character of the map for that tile. You probably want to add a type to the player object too, in line 26 of sprite.lua.

The initial player position is inside a wall. Fix that.

And please learn to debug your code yourself.

User avatar
bobbymcbobface
Citizen
Posts: 50
Joined: Tue Jun 04, 2019 8:31 pm

Re: help with collisions

Post by bobbymcbobface » Tue Sep 24, 2019 3:58 pm

Thanks pgimeno
pgimeno wrote:
Sun Sep 22, 2019 11:22 am


And please learn to debug your code yourself.
Sorry about that still learning the balance between asking the forums and working stuff out myself thnx for the advice
I make games that run on potatoes :P

Post Reply

Who is online

Users browsing this forum: Google [Bot], pedrosgali and 9 guests