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!
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
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
@@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!
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!
Good idea!
thank you for making these!!! your vids are so good for learning about this stuff :>>
This is great. Thank you so much. Please keep these coming.
Nice video. keep it with the good work
Thanks for the tutorial. I appreciate neat code too!
These are excellent videos!
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
Awesome, this helps
How would you make this more dynamic? I know my tiles will always be 8x8 but I don’t know there positions
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
Hi, could this collision code work with objects created by tables? For example, a table used to generate multiple enemy objects.
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.
@@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!
Thanks!