This is so well explained. I understand everything the first time, I see it. Due to your systematic approach, I even see your small errors before you correct them yourself :) . Thank you so much for your videos!
That happens to me! It's because the player is on a non-collidable tile, then when it adds dx its still on a non-collidable tile, same with dy but if it added dx and dy, it would find they collide.
Does anyone know if pico8 had any updates that make this code a little broken? I have the exact same code and the sprites with the same flags, but my character randomly changes direction even if I don't press any button, it looks like it "collides" with blank spaces on the map and then goes on a different axis. Here's the code: grid_x=0 grid_y=0 flag_tile=0 x=63 y=63 dx=0 dy=0 function _update() grid_x=flr(x/8) grid_y=flr(y/8) flag_tile=fget(mget(grid_x,grid_y),0) if btn(0) then dx=-1 end if btn(1) then dx=1 end if btn(2) then dy=-1 end if btn(3) then dy=1 end if hit(x+dx,y,7,7) then dx=0 end if hit(y+dy,x,7,7) then dy=0 end x+=dx y+=dy end function _draw() cls() map(0,0,0,0,16,16) spr(2,x,y) print(grid_x..","..grid_y,5,5,7) print(flag_tile,5,11) end function hit(x,y,w,h) collide=false for i=x,x+w,w do if fget(mget(i/8,y/8))>0 or fget(mget(i/8,(y+h)/8))>0 then collide=true end end return collide end
I cant seem to find my error. I followed the instructions and checked against your code. My sprite is colliding perfectly. However, it just continues to move in any direction I give it without stopping (unless colliding). Any suggestions?
Hello, I was unable to copy the code here. Is the sprite supposed to stop moving after pressing the arrow keys in your code? For example, in my version if I pressed left arrow once, it would go left but just continue until leaving the screen or hitting a wall.