Collisions in Pico-8 using the hit_box() function

Поділитися
Вставка
  • Опубліковано 11 січ 2025

КОМЕНТАРІ • 15

  • @ricardovelazquez7017
    @ricardovelazquez7017 3 роки тому +5

    Instead of adding values one by one all the time, you can check if the x+SPEED value is not going to collide and add the whole speed otherwise you add values one by one until you reach the collision point. Great tutorial!

  • @ultraivory
    @ultraivory 6 років тому +5

    thank you for making these!!! your vids are so good for learning about this stuff :>>

  • @NorthStateGames
    @NorthStateGames 4 роки тому +1

    This is great. Thank you so much. Please keep these coming.

  • @GodOfTetris90
    @GodOfTetris90 6 років тому +3

    Nice video. keep it with the good work

  • @guarokuya3678
    @guarokuya3678 5 років тому +2

    Thanks for the tutorial. I appreciate neat code too!

  • @bblevins
    @bblevins 2 роки тому

    These are excellent videos!

  • @jo-ellenphilander1230
    @jo-ellenphilander1230 4 роки тому +2

    Hi I am struggling to make this hit_box() function work with my code, here is what I have:
    I create and empty list of entities: entity_list = {}
    I create an entity like so and then call it in the _init() function with basic movement and no collision.
    I only reference the player and not any of the enemies. Please help.
    function _init()
    player = create_entity( 3, 3, 16, 16)
    create_entity(9, 9, 16, 16)
    end
    function create_entity(entity_x, entity_y, entity_width, entity_height)
    local entity = {
    x = entity_x,
    y = entity_y,
    width = entity_width,
    height = entity_height
    }
    add(entity_list, entity)
    return entity
    end

  • @PeetonJazzy
    @PeetonJazzy 6 років тому +3

    Awesome, this helps

  • @louisgjohnson
    @louisgjohnson 5 років тому +1

    How would you make this more dynamic? I know my tiles will always be 8x8 but I don’t know there positions

    • @docrobs
      @docrobs  5 років тому +3

      It's going to be tricky to do collisions if you don't know where something is! If you are just trying to do tile collisions, you should check out my video on fget and mget as they look into that sort of collision: ua-cam.com/video/Gs0XFViFxFs/v-deo.html

  • @willshrly76
    @willshrly76 5 років тому +1

    Hi, could this collision code work with objects created by tables? For example, a table used to generate multiple enemy objects.

    • @docrobs
      @docrobs  5 років тому +1

      Yes, provided you know the x and y location and the width and height you can use this method. You could loop through the objects collisions.

    • @macadamiaman4927
      @macadamiaman4927 4 роки тому

      ​@@docrobs Hi, I can't seem to get this to work. When I try to make collisions between my player (all their data is contained in a table) and a wall (an object in a table) by typing in:
      if btn(0) then
      for self.newx=self.x,self.x-self.speed,-1 do
      if not hit(self.x,self.y,self.w,self.h,
      w.x,w.y,w.w,w.h) then --w.x is the wall x, w.y is the wall y, etc.
      self.x=self.newx
      end
      end
      end
      Pico-8 comes back with an error message saying " '=' or 'in' expected near '.' " I feel like this may have something to do with the recent Pico-8 update (0.2.0i), because the -1 is all blue when I type it in, not a blue number with a white dash. Then again I'm really new to Pico-8, and don't know exactly how to diagnose the problem... do you have any ideas about this?
      By the way, your videos are very insightful, and have been a big help in getting to understand Pico-8. Thanks for making them!

  • @eboatwright_
    @eboatwright_ 4 роки тому +1

    Thanks!