An improved variant of this is to divide your move function into two parts where you check left/right first, then up/down - that way your player object would slide along the sides of the obstacle if you move diagonally.
@spacecat88 Жыл бұрын
Great point!
@mingomango4895 Жыл бұрын
And if you were to do that how would you?
@xxsilvericexx Жыл бұрын
@@mingomango4895 what worked for me is by making the part "if collaide(o) then o.x = lx o.y = ly end" be "if collaide(o) then o.x = lx end" so with out the y check, while then added one more that just had the y check, hope that helps
@p0kepengin592 Жыл бұрын
@@xxsilvericexx i don't get it???
@anonymouslyanonymous098 ай бұрын
@xxsilvericexx you get stuck on the horizontal walls then
@bigsalmon79733 ай бұрын
I really am a noob cause despite following your tutorials thus far, this looks like alien writing to me. I may need to come back to this at a later point but am loving your pico 8 stuff so far. I just started today and your videos have helped me make something I never thought I could already. Let alone in a few hours
@Vanniberna2 ай бұрын
I know the feeling as a fellow noob 🙂 I puzzled on this for some time too, but I went back to the previous videos on stuff like mget or map interaction and they are perfect stepping stones to this tutorial, if you watch or re-watch the previous ones you will have enough foundation to understand what's going on here, you just need to overcome the terror of seeing a foreign block of code for the first time. Personally, as a noob, it helps me to learn certain things on a "need-to-know" basis, especially since PICO-8 has such a huge community willing to share code and tips. E.g. I don't entirely understand the math behind player collision detection (divide this by 8 pixels what?), but I know that what I see here allows me to make it work with a sprite of that size and I understand the general logic behind the code and the function. To me, that's enough to move to the next step and integrate what I learned here into my own projects... I'll develop more awareness and mastery of the finer details as I go on and keep making games.
@zalhietzli2 ай бұрын
Great tutorial ! Very clear and to the point. The solution I came up with is kind of the other way around. First check for the sprite number of the tile adjacent to the player, then allow movement if there it's not a "collisionable" tile. As I am making a 2D platformer I have different functions for checking collisions with floor, walls and ceilings.
@Jacob-ol3zb6 ай бұрын
Thank you so much. I have been getting started with pico 8 and for whatever reason collisions have been tripping me up. I lost some motivation but this explanation has been really helpful and it inspires me to keep going.
@thefog134 ай бұрын
One thing about this is that with the collide(o) check in move(), it blocks all movement, not just the movement directly tied to collision. If moving horizontally (x axis) without colliding but ALSO trying to move vertically (y axis) and colliding, both get blocked- kind of an issue. I'm not sure how to fix this, so help would be tremendously appreciated!
@Jazkool Жыл бұрын
I stumbled across the same post about collision in PICO-8 just recently and was completely overwhelmed by the complexity. Your video explained everything in a ton of detail, I can't thank you enough!
@Krampy2 Жыл бұрын
Incredibly simple and well explained. Much better than the confusing Nerdy Teachers video.
@danielsoe4 Жыл бұрын
This is a solid video! Probably one of the most simple ways to get collisions working in pico8! Thanks for sharing
@SensibleChuckle Жыл бұрын
I love these compartmentalized tutorials!!
@AutMouseLabs8 ай бұрын
This was so well explained. Thank you very much!
@spacecat888 ай бұрын
Glad it was helpful!
@elizabethrowe5960 Жыл бұрын
What I would like to see next? Random numbers, so I can scatter half a dozen or so obstacles around my screen. This is a great series, even if you did sneak local versus global variables in on us. PICO-8 reminds me of my old Atari computers from back in the day. Nostalgia much, and your videos are a great enhancement. By the way, if you have a variable for your direction and only check the tile you're about to move into (before you move) you might could simplify your code a little bit. But it's great anyway. Thanks loads.
@hoshikawaa Жыл бұрын
sona pona a. Thanks for this excellent tutorial!!
@chichibekАй бұрын
Thanks good explanation
@amadeusfuzz43208 ай бұрын
Hello and thank you! I'm making my first game ever and your tutorials are great because I'm actually learning and not just copying. That being said, collision isn't working for me. I'm coming off of your video on player movement, so I have a player table set up with movement. I typed all the collision stuff in a new tab, and added move(player) under the update function above the direction arguments in the first tab. That might be where I'm going wrong? do you have other advice? im going to check out other vids in the meantime. I plan to buy your course in the near future, but I want to get my first game up first. thank you for being an awesome teacher!
@spacecat888 ай бұрын
Make sure that what you put inside of move() is the name of the table that holds your player stuff. So if it's player{x=64... Etc Then it would be nice(player). If your table is like plr{} or char{} it would be move(plr) or move(char) That feeds the player as the object that's going to move to the other function.
@amadeusfuzz43208 ай бұрын
@spacecat88 thank you so much for getting back to me! i implemented your suggestion. It made the error go away, but the game is running without collision. i ran the video again and followed my code to see if i missed anything. flags are checked, and my tab is exactly as yours with the (player) included. it might have something to do with the upade function in my first tab? or the local save? are there any quarks about that i should be aware of? sorry, i dont think like a programmer yet, but this is very fun. I have a clear idea that i want to bring to life and i appreciate all of your help.
@shanecoates1330 Жыл бұрын
HI! I just think it would be really neat if you copied and pasted the codes into the descriptions of your videos!
@eduardoteixeira50137 ай бұрын
I've double-checked my code dozens of times and everything seems right but the collision only works some of the time. I can move through a blocks some of the time, but it consistently blocks me from moving if im colliding with the lowest row of pixels on the flagged blocks. Thoughts?
@DrizzyB6 ай бұрын
First you said that the X1, Y1, X2, and Y2 correspond to the edges of a sprite, but then you say they correspond to corners later on. Which one is it?
@Monchy_105 ай бұрын
corners.
@guritche Жыл бұрын
an issue I ran into is that using LX and LY to jump back to the previous space works when the movement "speed is 1". If you change the player sped to +=4 for example, once it hists a collision the player jumps 4 pixels back.. still trying to avoid this on my code but no success yet.
@spacecat8811 ай бұрын
Yeah ive fixed this with combining the collision test into a for loop that tests each pixel up to the speed. So for instance 4x for 4px speed. Then wherever it hits, the sprite stops.
@Cheemsonabike10 ай бұрын
Hey spacecat, i tried this code and it works great but i have a question about how it works. I see move() is tied in with the player correct? function _update Move(plr) But in the Move function, btn (➡️) is tied to o.x. theres no mention of plr.x I don’t understand how o.x is affecting plr.x then 🤔
@spacecat8810 ай бұрын
Yeah the plr gets subbed in for the o it's a local variable just in that function. It's so you can put anything you want into the move() and it'll apply to that.
@guritche Жыл бұрын
unlike the 'find tile under your player' tutorial, you don't seem to use FLR to get an int on that division by 8? Seems to work still..
@spacecat889 ай бұрын
Yeah it rounds it anyway. So you don't really need flr
@KiffinGish7 ай бұрын
RETURN A OR B OR C OR D is better than an IF or not?
@maleficmax Жыл бұрын
Thank you for great series and explanations! I try to enable my object to slide by the wall when pressing diagonals and use try to use the proposal by @64jcl but my player slides only by vertical obstacles, not the horizontal ones. Do you have an idea why this is happening? Otherwise collision works great!
@anonymouslyanonymous098 ай бұрын
Same, I will let you know if I figure it out
@marcosadsjunior Жыл бұрын
Awesome explanation I really appreciate but doing this by tiles is kynda stay some gaps between the Player and other tiles because my player isn't every corner printed. It have a better way to solve this or I really need fill at least one pixel in every corner of player tile? Thanks a lot man
@spacecat88 Жыл бұрын
Yeah instead of checking the corners you can check any point closer to your player too. So bring the sides in a little basically. I like to have it a little smaller than my character so he can overlap just a smidge.
@hank2457 Жыл бұрын
@@spacecat88 hello - thanks so much for your tutorials, these are incredibly helpful! I have zero background in coding. Could you clarify how to "bring in the sides" in the code? Would you accomplish this by adjusting the "local x1=o.x/8" lines? Thanks again!
@seniormika Жыл бұрын
pretty understandable
@obuqwe Жыл бұрын
what sides to a b c and d correspond to?
@spacecat88 Жыл бұрын
In this case, they are the corners of the sprite, so it checks each corner to make sure there isn't any collision.
@firasbenghayadha2422 Жыл бұрын
can this work with shooting enemies ?
@spacecat88 Жыл бұрын
Yup! Although I like to use a simpler line that asks if an enemy is within a certain radius of a bullet. I'll make a bullet tutorial soon!
@burnlandgaming Жыл бұрын
i cant seem to get it to work, the movement works fine but the when i collide with an object i just go straight through it (yes i have flagged the player)
@spacecat88 Жыл бұрын
Hmmm .. the player doesn't need a flag, but the tiles you can't pass through do.
@kylethesurvivor3874 Жыл бұрын
Lol I was just looking this up earlier.
@r-pugnantecopycat Жыл бұрын
...what?
@remcogreve798210 ай бұрын
If something is true return true is useless code. You will see it a lot but it you can just return the Boolean.
@spacecat889 ай бұрын
Oh yeah that makes sense
@Dinglebingleton4 Жыл бұрын
I have the code perfect but it keeps saying unclosed function at line 22 tab 2
@balorprice Жыл бұрын
Press Escape directly after this error and it will take you to the offending line. It's likely there isn't an END keyword matching this - as long as you have indented the code well this should be easy to find