Bump.lua - collision not working

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
2lostsouls
Prole
Posts: 15
Joined: Sat May 25, 2019 9:33 pm

Bump.lua - collision not working

Post by 2lostsouls »

I found a great thread on this forum about how to use bump.lua. I was able to add it to my main.lua without an error. But when I move the player, the player is still going through the image of the desk. I put a square around the image and added a property called collideable and made it true as the tutorial states. I think I may have two problems:

1. I do not think I am referencing the player for the new world.
2. I don't have it on my map correctly.

Here is the code and two images showing what I did. Hopefully this helps. Thank you for any assistance.

Code: Select all

-- Include Simple Tiled Implementation into project
sti = require "sti"
bump = require "bump"


function love.load()
    -- Load map file
    map = sti("map.lua")
    
    local world = bump.newWorld()
    local map = sti('map.lua', {"bump"}) -- This loads the map file, and loads the bump plugin for STI
    map:bump_init(world) -- This initializes the bump plugin, and loads all of your collidable tiles
    

    -- Create new dynamic data layer called "Sprites" as the 3rd layer
    local layer = map:addCustomLayer("Sprites", 3)

    -- Get player spawn object
    local player
    for k, object in pairs(map.objects) do
        if object.name == "Player" then
            player = object
            break
        end
    end
    
  

    -- Create player object
    local sprite = love.graphics.newImage("sprite.png")
    img = love.graphics.newQuad(0, 0, 32, 64, sprite:getDimensions())
    layer.player = {
    sprite = sprite,
        x      = player.x,
        y      = player.y,
        ox     = sprite:getWidth() / 2,
        oy     = sprite:getHeight() / 1.35
  }
    
    

    -- Add controls to player
    layer.update = function(self, dt)
        -- 96 pixels per second
        local speed = 96

        -- Move player up
        if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
            self.player.y = self.player.y - speed * dt
        end

        -- Move player down
        if love.keyboard.isDown("s") or love.keyboard.isDown("down") then
            self.player.y = self.player.y + speed * dt
        end

        -- Move player left
        if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
            self.player.x = self.player.x - speed * dt
        end

        -- Move player right
        if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
            self.player.x = self.player.x + speed * dt
        end
    end
    
    

    -- Draw player
   layer.draw = function(self)
            love.graphics.draw(
            self.player.sprite,
           math.floor(self.player.x),
           math.floor(self.player.y),
           0,
           1,
           1,
           self.player.ox,
           self.player.oy
 )
    end

--   Remove unneeded object layer
   map:removeLayer("Spawn Point")



function love.update(dt)
    -- Update world
    map:update(dt)
end

function love.draw()
    -- Scale world
    local scale = 2
    local screen_width = love.graphics.getWidth() / scale
    local screen_height = love.graphics.getHeight() / scale

    map:draw()
  end
end[attachment=1]imageCollider.png[/attachment]
Attachments
imageCollider.png
imageCollider.png (98.13 KiB) Viewed 13744 times
User avatar
AdrianN
Citizen
Posts: 73
Joined: Wed Mar 28, 2018 5:13 pm
Location: Lima

Re: Bump.lua - collision not working

Post by AdrianN »

I think because in your collision filter you writed collideable instead of collidable.
I'm not sure, but you could try.

I recommend this tutorial, I used it when i used the bump library.

http://osmstudios.com/tutorials/love2d- ... ing-levels
2lostsouls
Prole
Posts: 15
Joined: Sat May 25, 2019 9:33 pm

Re: Bump.lua - collision not working

Post by 2lostsouls »

Thank you, I fixed that. I am just not sure if I am using Tiled correctly. There are not any detailed tutorials out there.

1. Do I put the sprite image on an image layer on the map after making the collidable tiles, or on an object layer?

Thank you for everyone's help.
User avatar
AdrianN
Citizen
Posts: 73
Joined: Wed Mar 28, 2018 5:13 pm
Location: Lima

Re: Bump.lua - collision not working

Post by AdrianN »

2lostsouls wrote: Wed Jun 19, 2019 1:54 pm 1. Do I put the sprite image on an image layer on the map after making the collidable tiles, or on an object layer?
I'm not sure, but I think the image layer and the object layer are identical, only one is dedicated to images.
STI admits both layers.
2lostsouls
Prole
Posts: 15
Joined: Sat May 25, 2019 9:33 pm

Re: Bump.lua - collision not working

Post by 2lostsouls »

Ok, I really want to learn this but it is getting very frustrating. I cannot get the collision to work. I cannot find a tutorial that really shows me how to do the collision. The picture shows my character but he is going right through the object that I want him not to go through. Is there any one that can look at the code and see if there is something I should be adding. I am showing some pics on how my tileset looks and my map as well as my Main.lua. Thank you.

Code: Select all

-- Include Simple Tiled Implementation into project
sti = require "sti"
bump = require "bump"


function love.load()
    -- Load map file
    map = sti("map.lua")
    
    local world = bump.newWorld()
    local map = sti('map.lua', {"bump"}) -- This loads the map file, and loads the bump plugin for STI
    map:bump_init(world) -- This initializes the bump plugin, and loads all of your collidable tiles
    

    -- Create new dynamic data layer called "Sprites" as the 3rd layer
    local layer = map:addCustomLayer("Sprites", 3)

    -- Get player spawn object
    local player
    for k, object in pairs(map.objects) do
        if object.name == "Player" then
            player = object
            break
        end
    end
    
  

    -- Create player object
    local sprite = love.graphics.newImage("sprite.png")
    img = love.graphics.newQuad(0, 0, 32, 64, sprite:getDimensions())
    layer.player = {
    sprite = sprite,
        x      = player.x,
        y      = player.y,
        ox     = sprite:getWidth() / 2,
        oy     = sprite:getHeight() / 1.35
  }
    
    

    -- Add controls to player
    layer.update = function(self, dt)
        -- 96 pixels per second
        local speed = 96

        -- Move player up
        if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
            self.player.y = self.player.y - speed * dt
        end

        -- Move player down
        if love.keyboard.isDown("s") or love.keyboard.isDown("down") then
            self.player.y = self.player.y + speed * dt
        end

        -- Move player left
        if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
            self.player.x = self.player.x - speed * dt
        end

        -- Move player right
        if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
            self.player.x = self.player.x + speed * dt
        end
    end
    
    

    -- Draw player
   layer.draw = function(self)
            love.graphics.draw(
            self.player.sprite,
           math.floor(self.player.x),
           math.floor(self.player.y),
           0,
           1,
           1,
           self.player.ox,
           self.player.oy
 )
    end

--   Remove unneeded object layer
   map:removeLayer("Spawn Point")



function love.update(dt)
    -- Update world
    map:update(dt)
end

function love.draw()
    -- Scale world
    local scale = 2
    local screen_width = love.graphics.getWidth() / scale
    local screen_height = love.graphics.getHeight() / scale

    map:draw()
  end
end
Attachments
tileset1.png
tileset1.png (98.73 KiB) Viewed 13562 times
map.png
map.png (86.02 KiB) Viewed 13562 times
character.png
character.png (30.63 KiB) Viewed 13562 times
User avatar
AdrianN
Citizen
Posts: 73
Joined: Wed Mar 28, 2018 5:13 pm
Location: Lima

Re: Bump.lua - collision not working

Post by AdrianN »

2lostsouls wrote: Fri Jun 21, 2019 1:39 am Ok, I really want to learn this but it is getting very frustrating. I cannot get the collision to work. I cannot find a tutorial that really shows me how to do the collision. The picture shows my character but he is going right through the object that I want him not to go through. Is there any one that can look at the code and see if there is something I should be adding. I am showing some pics on how my tileset looks and my map as well as my Main.lua. Thank you.

Code: Select all

-- Include Simple Tiled Implementation into project
sti = require "sti"
bump = require "bump"


function love.load()
    -- Load map file
    map = sti("map.lua")
    
    local world = bump.newWorld()
    local map = sti('map.lua', {"bump"}) -- This loads the map file, and loads the bump plugin for STI
    map:bump_init(world) -- This initializes the bump plugin, and loads all of your collidable tiles
    

    -- Create new dynamic data layer called "Sprites" as the 3rd layer
    local layer = map:addCustomLayer("Sprites", 3)

    -- Get player spawn object
    local player
    for k, object in pairs(map.objects) do
        if object.name == "Player" then
            player = object
            break
        end
    end
    
  

    -- Create player object
    local sprite = love.graphics.newImage("sprite.png")
    img = love.graphics.newQuad(0, 0, 32, 64, sprite:getDimensions())
    layer.player = {
    sprite = sprite,
        x      = player.x,
        y      = player.y,
        ox     = sprite:getWidth() / 2,
        oy     = sprite:getHeight() / 1.35
  }
    
    

    -- Add controls to player
    layer.update = function(self, dt)
        -- 96 pixels per second
        local speed = 96

        -- Move player up
        if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
            self.player.y = self.player.y - speed * dt
        end

        -- Move player down
        if love.keyboard.isDown("s") or love.keyboard.isDown("down") then
            self.player.y = self.player.y + speed * dt
        end

        -- Move player left
        if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
            self.player.x = self.player.x - speed * dt
        end

        -- Move player right
        if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
            self.player.x = self.player.x + speed * dt
        end
    end
    
    

    -- Draw player
   layer.draw = function(self)
            love.graphics.draw(
            self.player.sprite,
           math.floor(self.player.x),
           math.floor(self.player.y),
           0,
           1,
           1,
           self.player.ox,
           self.player.oy
 )
    end

--   Remove unneeded object layer
   map:removeLayer("Spawn Point")



function love.update(dt)
    -- Update world
    map:update(dt)
end

function love.draw()
    -- Scale world
    local scale = 2
    local screen_width = love.graphics.getWidth() / scale
    local screen_height = love.graphics.getHeight() / scale

    map:draw()
  end
end
http://karai17.github.io/Simple-Tiled-I ... p.lua.html

collidable set to true, can be used on any Layer, Tile, or Object

You need to rename collidable instead of Collidable and variable boolean type

Image
2lostsouls
Prole
Posts: 15
Joined: Sat May 25, 2019 9:33 pm

Re: Bump.lua - collision not working

Post by 2lostsouls »

Ok, thank you. I did that but still not working.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Bump.lua - collision not working

Post by Karai17 »

Have you looked at the tutorial that is in the github repo?

https://github.com/karai17/Simple-Tiled ... -to-sti.md
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
AdrianN
Citizen
Posts: 73
Joined: Wed Mar 28, 2018 5:13 pm
Location: Lima

Re: Bump.lua - collision not working

Post by AdrianN »

2lostsouls wrote: Fri Jun 21, 2019 1:39 am Ok, I really want to learn this but it is getting very frustrating. I cannot get the collision to work. I cannot find a tutorial that really shows me how to do the collision. The picture shows my character but he is going right through the object that I want him not to go through. Is there any one that can look at the code and see if there is something I should be adding. I am showing some pics on how my tileset looks and my map as well as my Main.lua. Thank you.

Code: Select all

-- Include Simple Tiled Implementation into project
sti = require "sti"
bump = require "bump"


function love.load()
    -- Load map file
    map = sti("map.lua")
    
    local world = bump.newWorld()
    local map = sti('map.lua', {"bump"}) -- This loads the map file, and loads the bump plugin for STI
    map:bump_init(world) -- This initializes the bump plugin, and loads all of your collidable tiles
    

    -- Create new dynamic data layer called "Sprites" as the 3rd layer
    local layer = map:addCustomLayer("Sprites", 3)

    -- Get player spawn object
    local player
    for k, object in pairs(map.objects) do
        if object.name == "Player" then
            player = object
            break
        end
    end
    
  

    -- Create player object
    local sprite = love.graphics.newImage("sprite.png")
    img = love.graphics.newQuad(0, 0, 32, 64, sprite:getDimensions())
    layer.player = {
    sprite = sprite,
        x      = player.x,
        y      = player.y,
        ox     = sprite:getWidth() / 2,
        oy     = sprite:getHeight() / 1.35
  }
    
    

    -- Add controls to player
    layer.update = function(self, dt)
        -- 96 pixels per second
        local speed = 96

        -- Move player up
        if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
            self.player.y = self.player.y - speed * dt
        end

        -- Move player down
        if love.keyboard.isDown("s") or love.keyboard.isDown("down") then
            self.player.y = self.player.y + speed * dt
        end

        -- Move player left
        if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
            self.player.x = self.player.x - speed * dt
        end

        -- Move player right
        if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
            self.player.x = self.player.x + speed * dt
        end
    end
    
    

    -- Draw player
   layer.draw = function(self)
            love.graphics.draw(
            self.player.sprite,
           math.floor(self.player.x),
           math.floor(self.player.y),
           0,
           1,
           1,
           self.player.ox,
           self.player.oy
 )
    end

--   Remove unneeded object layer
   map:removeLayer("Spawn Point")



function love.update(dt)
    -- Update world
    map:update(dt)
end

function love.draw()
    -- Scale world
    local scale = 2
    local screen_width = love.graphics.getWidth() / scale
    local screen_height = love.graphics.getHeight() / scale

    map:draw()
  end
end
I think you need to register the position of you shape in bump word. And check if you can move it.

Code: Select all

world:add(A,   0, 0,    64, 256)
...
local actualX, actualY, cols, len = world:move(B, 0,64)
https://github.com/kikito/bump.lua

Tutorial Bump-Tiled : http://osmstudios.com/tutorials/love2d- ... ing-levels
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Bump.lua - collision not working

Post by kikito »

Hi, bump author here.

It seems to me that there is something wrong with your "update" function. If you are using bump you should never be doing something like this:

Code: Select all

if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
  self.player.y = self.player.y - speed * dt
end
The way bump works is by telling it "hey I want to move this object from where it is to *{x,y}*". Then bump "processes the attempt" and gives you a new x and y ("ok, this is where your object ended up when attempting to move to {x,y}") and a list of collisions ("and this is the list of objects it collided with"). This is done with the *world:move* method. See this link:

https://github.com/kikito/bump.lua#movi ... resolution
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests