Easy Pico-8 Collision Function - Simple Collision Explained!

  Рет қаралды 11,374

SpaceCat

SpaceCat

Күн бұрын

Пікірлер: 52
@64jcl
@64jcl Жыл бұрын
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
@spacecat88 Жыл бұрын
Great point!
@mingomango4895
@mingomango4895 Жыл бұрын
And if you were to do that how would you?
@xxsilvericexx
@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
@p0kepengin592 Жыл бұрын
@@xxsilvericexx i don't get it???
@anonymouslyanonymous09
@anonymouslyanonymous09 8 ай бұрын
​@xxsilvericexx you get stuck on the horizontal walls then
@bigsalmon7973
@bigsalmon7973 3 ай бұрын
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
@Vanniberna
@Vanniberna 2 ай бұрын
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.
@zalhietzli
@zalhietzli 2 ай бұрын
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-ol3zb
@Jacob-ol3zb 6 ай бұрын
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.
@thefog13
@thefog13 4 ай бұрын
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
@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
@Krampy2 Жыл бұрын
Incredibly simple and well explained. Much better than the confusing Nerdy Teachers video.
@danielsoe4
@danielsoe4 Жыл бұрын
This is a solid video! Probably one of the most simple ways to get collisions working in pico8! Thanks for sharing
@SensibleChuckle
@SensibleChuckle Жыл бұрын
I love these compartmentalized tutorials!!
@AutMouseLabs
@AutMouseLabs 8 ай бұрын
This was so well explained. Thank you very much!
@spacecat88
@spacecat88 8 ай бұрын
Glad it was helpful!
@elizabethrowe5960
@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
@hoshikawaa Жыл бұрын
sona pona a. Thanks for this excellent tutorial!!
@chichibek
@chichibek Ай бұрын
Thanks good explanation
@amadeusfuzz4320
@amadeusfuzz4320 8 ай бұрын
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!
@spacecat88
@spacecat88 8 ай бұрын
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.
@amadeusfuzz4320
@amadeusfuzz4320 8 ай бұрын
@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
@shanecoates1330 Жыл бұрын
HI! I just think it would be really neat if you copied and pasted the codes into the descriptions of your videos!
@eduardoteixeira5013
@eduardoteixeira5013 7 ай бұрын
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?
@DrizzyB
@DrizzyB 6 ай бұрын
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_10
@Monchy_10 5 ай бұрын
corners.
@guritche
@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.
@spacecat88
@spacecat88 11 ай бұрын
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.
@Cheemsonabike
@Cheemsonabike 10 ай бұрын
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 🤔
@spacecat88
@spacecat88 10 ай бұрын
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
@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..
@spacecat88
@spacecat88 9 ай бұрын
Yeah it rounds it anyway. So you don't really need flr
@KiffinGish
@KiffinGish 7 ай бұрын
RETURN A OR B OR C OR D is better than an IF or not?
@maleficmax
@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!
@anonymouslyanonymous09
@anonymouslyanonymous09 8 ай бұрын
Same, I will let you know if I figure it out
@marcosadsjunior
@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
@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
@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
@seniormika Жыл бұрын
pretty understandable
@obuqwe
@obuqwe Жыл бұрын
what sides to a b c and d correspond to?
@spacecat88
@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
@firasbenghayadha2422 Жыл бұрын
can this work with shooting enemies ?
@spacecat88
@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
@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
@spacecat88 Жыл бұрын
Hmmm .. the player doesn't need a flag, but the tiles you can't pass through do.
@kylethesurvivor3874
@kylethesurvivor3874 Жыл бұрын
Lol I was just looking this up earlier.
@r-pugnantecopycat
@r-pugnantecopycat Жыл бұрын
...what?
@remcogreve7982
@remcogreve7982 10 ай бұрын
If something is true return true is useless code. You will see it a lot but it you can just return the Boolean.
@spacecat88
@spacecat88 9 ай бұрын
Oh yeah that makes sense
@Dinglebingleton4
@Dinglebingleton4 Жыл бұрын
I have the code perfect but it keeps saying unclosed function at line 22 tab 2
@balorprice
@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
Particles in Pico-8 - The Ultimate Guide
16:49
SpaceCat
Рет қаралды 7 М.
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 82 МЛН
Import an instance of a class into an Angular component
1:15
PICO 8 Tips | Using External Tools
15:23
Kevin Makes Games
Рет қаралды 15 М.
Set Up Your Player - THE RIGHT WAY! - Using Classes in Pico-8
11:28
Basic Sprite Function - SPR() - Pico 8 Tutorial
7:41
Nerdy Teachers
Рет қаралды 7 М.
Creating objects using tables in Pico-8
14:44
doc_robs
Рет қаралды 9 М.
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 199 М.
Let's make a PICO-8 Game in 30 Minutes!
30:18
GDC 2025
Рет қаралды 76 М.
New Secret Colors! | PICO-8
23:11
Lazy Devs
Рет қаралды 24 М.