Page 1 of 1

Bump.lua - collision not working

Posted: Mon Jun 17, 2019 1:16 am
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]

Re: Bump.lua - collision not working

Posted: Tue Jun 18, 2019 6:34 pm
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

Re: Bump.lua - collision not working

Posted: Wed Jun 19, 2019 1:54 pm
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.

Re: Bump.lua - collision not working

Posted: Wed Jun 19, 2019 8:25 pm
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.

Re: Bump.lua - collision not working

Posted: Fri Jun 21, 2019 1:39 am
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

Re: Bump.lua - collision not working

Posted: Fri Jun 21, 2019 3:32 am
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

Re: Bump.lua - collision not working

Posted: Fri Jun 21, 2019 6:50 pm
by 2lostsouls
Ok, thank you. I did that but still not working.

Re: Bump.lua - collision not working

Posted: Sat Jun 22, 2019 5:26 pm
by Karai17
Have you looked at the tutorial that is in the github repo?

https://github.com/karai17/Simple-Tiled ... -to-sti.md

Re: Bump.lua - collision not working

Posted: Sat Jun 22, 2019 6:57 pm
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

Re: Bump.lua - collision not working

Posted: Wed Jul 03, 2019 2:50 pm
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