what the hell, dude being haunted in 1:09 and kept recording, absolute legend.
@envar1
2 ай бұрын
The sound is Japanese police driving by his building
@jumpsneak
2 жыл бұрын
best Programming series on youtube
@samjesf
Жыл бұрын
For anyone who may run into the same problem I was, where despite my code being the same as what is in the video, my player character wouldn't move, make sure that you have '==' in your if statements and not a singular '='. I was overlooking this because it's such a small detail, but it was making the body of my if statements unreachable and preventing movement. After changing this, my character was able to move.
@happyburger23
Жыл бұрын
When I do that, I'm getting an error reading "Not a statement". How do I fix that?
@antoinebguitar2869
5 ай бұрын
Its makes huge difference. In programming == typically means to check if a certain value is equal to another, typically used in if statement, while a single = just assign the value so yeah it literally changes meaning so of course it will not work. It's not what i would call small detail haha
@Tefrax
Жыл бұрын
Thank you, RyiSnow, this is a wonderful series. Learning a lot! A small addition: If you still want to be able to change the scale factor one should base the collision rectangle coordinates on the 16x16 image (not the 48x48) and multiply it by the scale factor upon initializing it in the player class.
@hakerananasek
Жыл бұрын
Yess glad someone pointed it out. Those fixed numbers looked out of place to me lol
@BracamonteL
7 күн бұрын
I was stuck for a couple of days and then the solution came to me in a dream source: a dream
@savkorlev
2 жыл бұрын
Man, you're a legend, thank you for your tutorials! 👍
@RyiSnow
2 жыл бұрын
Glad you like them! Thank you for the comment.
@natzos6372
Жыл бұрын
If your character get stuck on collisions sometimes, check if changed the - to a + in case "down" and case "right" in the CollisionChecker.
@xcuze
Жыл бұрын
you're the goat thanks :P
@Julson_PL
Жыл бұрын
Thank you too.
@thiccboiigavin5341
11 ай бұрын
tysm
@AlexanderHL1919
5 ай бұрын
Great video! I just want to mention since theres a few people in the comments who ran in the same issue, there is an issue when "solidArea.x" is made equal to a ratio of the "tileSize" if you want to maintain the "scale" functionality because it is integer division and the compiler will round it up or down to unpredictable number and the collision detection will work very strangely as the collision box will not be where you expect it. The solution is to use hardcoded numbers like in the video, or make the tileSize a "double" and not "int", but this would require everything else that tileSize interacts with to be recast to double instead of int. I'm guessing this is why you used numbers in the video instead of tileSize.
@jwfinn100
Жыл бұрын
For anyone who finds their player character gets stuck, make sure that you have a ‘break’ in each switch statement for the collision checking. Otherwise all 4 collision checks are done for each movement and you’ll get stuck.
@hanno-oz3ip
2 жыл бұрын
hope this tutorial series never ends
@Kandiman911
2 жыл бұрын
Thank you so much, I really enjoy these videos they're so helpful, you deserve so much more views!
@Mypremiumacct
3 ай бұрын
Been following along the past few days and have felt so proud where I am thanks to you. I cant wait till I learn more so I can add quests and npcs!
@六工業のカービィ
2 жыл бұрын
With great help of your videos I might be able to make a tile based strategy, and then a 3D version of it, and not only it. Thanks for the help 🙂😌
@rexroyulada6267
5 ай бұрын
Also, make sure that you let the entity check the direction it is colliding, example: I don't know what this: entityRightCol = (entityRightWorldX + entity.spd) / (gp.tileSize); was used for and even accidentally did this instead: entityRightWorldX += entity.spd / gp.tileSize; This part of the code actually detects the collision before the entity gets too close to the tile and detect multiple collisions. I learned this the hard way.
@bluethemcguy4430
2 жыл бұрын
Also thanks for making this series, i needed it so much!
@kandiman9111
2 жыл бұрын
Another great video, these are so helpful and really appreciated, thanks so much!
@RyiSnow
2 жыл бұрын
You're welcome! Glad I could help :)
@droidlycodes
2 жыл бұрын
I can't wait to jump in on this guide as I've tried to understand how collision was detected for a while. Your guide is the only one I understand!
@redwings1847
22 күн бұрын
I'm always writing comments for what each block of code does so when running into some problem I can quickly review that specific block of code to fix any issues. For comments, explanations for what the code does explained in this video works good for comments. This series is pretty long and getting to the end without comments would make all the code really difficult to understand later I think.
@yuvtajvirsingh3513
2 жыл бұрын
Thanks for the video, I was confused on how to implement a Collision Detection
@tranminhquang7368
2 жыл бұрын
I've been waiting for your new video for 1 week Hope you make more videos in the future
@RyiSnow
2 жыл бұрын
I have a full time job so can't promise but hopefully I can spend more time for making videos this month.
@mehmetjj9163
2 жыл бұрын
you are a man of honor
@vasilisavasya4245
2 жыл бұрын
your videos are indeed very clear and helpful
@BrunoHenrique-oe5hb
10 ай бұрын
When i change the player.update() to implement the collision system i had a problem: when the game starts my character starts move down automaticaly. This happened because of two things: 1 - we change the way we increment the player position in the world. Before was in the if statment: if (keyH.upPressed == true) { direction = "up"; worldY -= speed; } then it was in the switch case: switch (direction) { case "up": worldY -= speed; break; 2 - i did no include t[he if statment: if(keyH.upPressed || keyH.downPressed || keyH.leftPressed || keyH.rightPressed) { // code } because i liked the player moving still, its like a breathing animation. But i couldn figure it out how to fix this without adding the conditional, sadly. But its ok, let's keep going. Great video, as always
@coldbacon冷気
7 ай бұрын
thank you very much, i had the same issue
@vistasinconnection9678
3 ай бұрын
Yay! got it working - this is really good. Teaching me so much. Thank you
@drec_is_here5229
8 ай бұрын
Update: in checkTile function I’ve found an issue regarding collision detection make sure to add spacing between the front slash “/“ or else its considered a division (example: entityTopRow - entity.speed / gp.tileSize) this one was very difficult to find since its the exact same thing I see on the video. Hope this helps
@Gm_hshahahs
8 ай бұрын
I think you forgot to put entity entityTopWorldY - entity.speed in bracket Like this (entityTopWorldY - entity.speed)/gp.tileSize;
@bluethemcguy4430
2 жыл бұрын
Loved the vid! I was wondering if you would incorporate random terrain generation in your game?
@RyiSnow
2 жыл бұрын
Not in this one. This is for 2D game beginners and I'm trying to keep it simple so the code is not overwhelmingly complicated (You'll need to construct an algorithm to do random generation). Maybe I will do in the future though.
@bluethemcguy4430
2 жыл бұрын
@@RyiSnow Ok, thank you for replying!
@droidlycodes
2 жыл бұрын
I have an idea for this based off my knowledge and how games like Minecraft are loaded. I'll see what I can come up with!
@elginbeloy9066
2 жыл бұрын
For something simple could use a markov process where tile probability is based on tiles neighbors. This would generate clusters like forests, oceans (w/ sand) or other things depending on those probability values. Tweak and have fun:)
@jojo.-tv
5 ай бұрын
If u have the problem that u ato walk after u included the collision for the "up" statement is here the solution: Import the code (to be seen at 22:44) on top to stop it from looping. It was created a few parts ago to make the player stop moving when hes standing. Hope I can help.
@alialden1258
2 жыл бұрын
Thank you so much for these tutorials
@DravenFNM
2 жыл бұрын
Was waiting eagerly for this video Thanks :)
@VasiliyNikitin
Жыл бұрын
Cool video tutorial! The result of this video makes me happy
@pasinducharuka9846
2 жыл бұрын
This is a great great great work... big salute to you bro...
@md.towhidulislamrahat2603
Жыл бұрын
Man Loved This tutorial. You're legend
@norhasanrajahmuda8509
3 ай бұрын
why my player continues moving down even if i did not control it and when i switch to right or left if also continue moving and when up is stop
@Ty-vm5hv
2 жыл бұрын
really nice tutorial, thanks a lot ! you deserve way more views !
@doxuantruong04
3 ай бұрын
Hey, I cannot create the collisionChecker function and receive the GamePanel gp.
@NikitaBomba112
Жыл бұрын
Thanks you so much for this video!
@jay_codes
2 жыл бұрын
Great Tutorial as always
@sgsnake2x
2 жыл бұрын
Could I make method such as this? public void createTile( int tileIndex, String filePath, boolean collision) throws IOException { tile [ tileIndex ] = new Tile(); tile[ tileIndex ] . image = ImageIO . read (getClass() . getResourceAsStream ( filePath ) ) ; tile [ tileIndex ] .collision = collision ; }
@laz3664
Жыл бұрын
I can't thank you enough for these!!
@MetinCloup
2 жыл бұрын
thank you for adding collision. i want ed this tutorial from you i make comment before about collision
@RyiSnow
2 жыл бұрын
Hope this helped!
@omerfaruk4579
9 ай бұрын
Nice brA, you are deserved to be BIG THREE ecole
@SlothfulSage285
2 жыл бұрын
Enjoyed it!
@thangduong1107
2 жыл бұрын
i love your videos very much
@RyiSnow
2 жыл бұрын
Glad to hear that!
@Locras
2 жыл бұрын
super video as always
@klanehz6291
2 жыл бұрын
daaaamn thaanks i was waiting for it haha
@MvpMartell
2 жыл бұрын
Hello Ryi this is Martell. How are you? Question: This question is a bit off topic so I apologize, but I want to know....how can I make JText field transparent? I tried to set the main text area to Opaque and that doesn't work. I even tried to set the background color to 0,0,0,0 and that didn't work either. I also tried to set the panel itself to OPAQUE and that didn't work. Can it be done?
@RyiSnow
2 жыл бұрын
JTextField tf = new JTextField(); tf.setOpaque(false); tf.setBorder(null); This makes it transparent.
@wizco4443
Жыл бұрын
Soo I have a problem, whenever I colode with an tree up down or left I can use the opposite direction to move away. If I collide with something on my right side the only way I can get out of colliding is if I go up or down , when I press left the animation plays but I don't go anywhere. PLEASE HELP! all help/ advice is welcome.......
@_chaozgt_
2 жыл бұрын
I've actually been having a bit of trouble when it came to player movement after moving the world speed to the if-statement: if(collisionOn == false) for the player class. For me, after making this change, the player just keeps moving in whatever direction that it is facing. The problem started at around 22:50 for reference. Any ideas that could have caused this problem?
@RyiSnow
2 жыл бұрын
May I see your Player class? You can paste it here.
@ciTatic
2 жыл бұрын
Looking at the code again, I think I see the issue: all of the movement code is running under an if statement that checks if a key is pressed. I don't have this for some reason and found my own workaround, but you could probably just add that if statement under update() in player. Look for it on line 71 in the video, or you can see it at 22:22 Without this if statement, the only guard on applying speed to position is whether you're colliding or not, and as you usually aren't colliding at this point in the video you'll just move forever.
@_chaozgt_
2 жыл бұрын
@@RyiSnow package tWoD.src.Entity; import java.awt.image.BufferedImage; import java.awt.*; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; import tWoD.*; import tWoD.src.Entity.*; import tWoD.src.Main.TwoDGamePanel; import tWoD.src.Main.TwoDKeyHandler; public class Plr extends Entity{ TwoDGamePanel gp; TwoDKeyHandler keyH; public final int screenX; public final int screenY; public Plr(TwoDGamePanel gp, TwoDKeyHandler keyH){ this.gp = gp; this.keyH = keyH; screenX = gp.screenWidth / 2 - (gp.tileSize / 2); screenY = gp.screenHeight / 2 - (gp.tileSize / 2); solidArea = new Rectangle(12, 18, 24, 30);//works by x,y,width,height setDefaultValues(); getPlayerImage(); } public void setDefaultValues(){ worldX = gp.tileSize * 25; worldY = gp.tileSize * 25; speed = 4; direction = "down"; } public void getPlayerImage(){ try{ left1 = ImageIO.read(getClass().getResourceAsStream("..\ sc\\Player\ obotPlayerAWalk_1.png")); left2 = ImageIO.read(getClass().getResourceAsStream("..\ sc\\Player\ obotPlayerAWalk_2.png")); right1 = ImageIO.read(getClass().getResourceAsStream("..\ sc\\Player\ obotPlayerDWalk_1.png")); right2 = ImageIO.read(getClass().getResourceAsStream("..\ sc\\Player\ obotPlayerDWalk_2.png")); down1 = ImageIO.read(getClass().getResourceAsStream("..\ sc\\Player\ obotPlayerSWalk_1.png")); down2 = ImageIO.read(getClass().getResourceAsStream("..\ sc\\Player\ obotPlayerSWalk_2.png")); up1 = ImageIO.read(getClass().getResourceAsStream("..\ sc\\Player\ obotPlayerWWalk_1.png")); up2 = ImageIO.read(getClass().getResourceAsStream("..\ sc\\Player\ obotPlayerWWalk_2.png")); }catch(IOException e){ e.printStackTrace(); } } public void update(){ if(keyH.upPressed == true){ direction = "up"; } else if(keyH.downPressed == true){ direction = "down"; } else if(keyH.leftPressed == true){ direction = "left"; } else if(keyH.rightPressed == true){ direction = "right"; } // CHECK TILE COLLISION collisionOn = false; gp.cChecker.checkTile(this); // IF COLLISION IS FALSE, PLAYER CAN MOVE if(collisionOn == false){ switch(direction){ case "up": worldY -= speed; break; case "down": worldY += speed; break; case "left": worldX -= speed; break; case "right": worldX += speed; break; } } spriteCounter++; if(spriteCounter > 15){ if(spriteNum == 1){ spriteNum = 2; } else if(spriteNum == 2){ spriteNum = 1; } spriteCounter = 0; } } public void draw(Graphics2D g2){ //g2.setColor(Color.white); // colors g2 - ismael notes //g2.fillRect(x, y, gp.tileSize, gp.tileSize); // placeholder for player character thus making it the size of tileSize - ismael notes BufferedImage image = null; switch(direction){ case "up": if(spriteNum == 1){ image = up1; } if(spriteNum == 2){ image = up2; } break; case "down": if(spriteNum == 1){ image = down1; } if(spriteNum == 2){ image = down2; } break; case "left": if(spriteNum == 1){ image = left1; } if(spriteNum == 2){ image = left2; } break; case "right": if(spriteNum == 1){ image = right1; } if(spriteNum == 2){ image = right2; } break; } g2.drawImage(image, screenX, screenY, gp.tileSize, gp.tileSize, null); } }
@RyiSnow
2 жыл бұрын
@@_chaozgt_ Just like ciTatic says, you haven't added the if statement to check key input. So the program keeps adding the speed value to player's worldX/Y. I guess you skipped a part in Part 3 video.
@_chaozgt_
2 жыл бұрын
@@RyiSnow Oh, i see, thank you!
@anniee2424
3 ай бұрын
THANK YOU SO SO SO MUCH!!!
@hakerananasek
Жыл бұрын
Hi Ryi, not sure if you're still reading the comments on your old videos, but there's a problem with collision rectangle object size not being dependent on scale. If you change the scale variable, the collision rectangle will still have the x, y, width and height as if the tileSize was 48. It can be fixed with multiplying rectangle arguments by scale. However, when I tested that, I also noticed that player moves faster on lower resolutions, and slower at higher. Is it intended, or addressed in later videos?
@toasty6224
Жыл бұрын
What do you mean by that? I’m currently building the game but I’m having issues with the collision. My characters width and height that I want for collision is 13 x 13. It is 9 pixels from the left border and 19 pixels away from the top border. However the issue is I’m still colliding with the actual tile size of 48 x 48 if I get to close to a tree for example.
@freshie94
10 ай бұрын
You could also move setting the image and collision into the constructor of tile, and just pass in the tile name to the Tile constructor, then in the getResourceAsStream you just pass in "/tiles/+name+".png". My list in the getTileImage became like this then: public void getTileImage() { tiles[0] = new Tile("grass", false); tiles[1] = new Tile("brickwall", true); tiles[2] = new Tile("water", true); tiles[3] = new Tile("earth", false); tiles[4] = new Tile("sand", false); tiles[5] = new Tile("tree", true); } And my Tile class: public class Tile { public String name; public BufferedImage image; public boolean collision; public Tile(String name, boolean collision) { this.name = name; this.collision = collision; this.image = getImage(); } private BufferedImage getImage() { BufferedImage image = null; try { image = ImageIO.read(getClass().getResourceAsStream("/tiles/" + name + ".png")); } catch (IOException e) { e.printStackTrace(); } return image; } }
@contrasena5243
2 жыл бұрын
I've watched this video 3-4 times in the last week and I can't understand a single thing on your checkTile method hahaha... I've seen in google that the Rectangle class has a collision method, would it be possible to use that method to make it simpler? Also I read a comment of a guy asking for randon terrain generation and that would be awesome. Greetings from Spain and thank you so much for these videos Im learning a lot! :)
@cedricsahaghian1605
Жыл бұрын
Thanks a lot for these videos!
@kevincolgan6651
2 жыл бұрын
Thanks so much for this
@iplay3542
4 ай бұрын
I really don’t know what’s wrong with my collision detection, my character is still going through blocks it’s not suppose to and stopping blocks it is suppose to, and my character is a 16x16
@youreawesome718
9 ай бұрын
So I've been having an issue with the collision. The map is loaded fine, however I will run into seemingly random collision areas on the map, and sometimes where there should be collision there isn't. I have redone the collision from this video, I have looked at the line string input for the map, made sure the correct tiles have had collision on. I am unsure where to go from here.
@youreawesome718
9 ай бұрын
Also what is the counter2 initializing in the player subclass?
@youreawesome718
9 ай бұрын
Well, the issue(which I haven't resolved) is the world01.txt is only loading half the map but making that half take up the 50x50 allocated tile slots. The bottom half will load but not the top. if I change maxWorldX and maxWorldY to 100, the map does not load with any of the textured tiles other than the grass tiles.
@princea08999
7 ай бұрын
@@youreawesome718 seems like problem is caused by the use of incorrect variables.
@زینبتوانا-غ3ز
Жыл бұрын
God bless you your videos helped me so much thank you thank you
@OneLatteComingRightUp
Жыл бұрын
Hi RyiSnow, I'm loving your content! I am currently up to episode 14 of the series, as I just found this amazing channel, except I have ignored a problem on how if I switch keys really fast next to an object, I can noclip through it, the NPC also knows how to do it! Can you please help me? Also, if I am not on the center of an object, but a bit lower, I can move through the object, as if the tree is a pixel small.
@MrSlinky
2 жыл бұрын
Great videos, they're helping a ton. I do have a question though. If my character collides with an object going up or down, they suddenly can't move side to side. I can't really seem to figure out what the problem is.
@MrSlinky
2 жыл бұрын
Nevermind I fixed it. It was because I was trying to use a double speed and so had to cast speed as an int in the collision detection class, so it was rounding the speed slightly lower than it should have, there for triggering the side to side collisions.
@deadsuch3930
16 күн бұрын
what if i just stuck on invisible tile i just go up and hey invisible wall how can i fix this i dont get it or i just go through collision tile why the method doesnt work though that code is correct.
@3bood_kr
Жыл бұрын
I'm trying to make pacman game using your code but the collision detection isn't working. So when i loaded the map i created an arraylist of rectangils of all blocks on the map that holdes each block x and y. And inside CollisionChecker i have a method that takes an entity as a parameter and loops over all the rectangles arraylist and checks if the player intersects with any of them using intersects method. So, is what i'm doing right? Cause it's not working. It's not giving any errors but the player can still walkthrough blocks. Edit: I fixed it by updating player's solidArea's cordinates in player's update method and also figured that i didn"t calculate the speed inside collision checker and now it's working. Now i'm trying to implement pacman movement by storing the next direction in a string and checking if the next direction's casues collision or not to decide when to change the current direction. Edit1: Finally i've succeeded to implement pacman's movement. It took me hours because he was getting stuck when he tried to enter a tight turn but somehow it worked at the end. I also added the food and implemented food interaction and now he can eat food and store score hos score. The only thing left is adding ghosts and sounds.
@TerminallyUnique95
2 жыл бұрын
How can I troubleshoot by drawing the collision rectangles on screen. My character is able to pass through top left and bottom left of solid objects.
@RyiSnow
2 жыл бұрын
You can display the rectangle by adding a line like this: g2.drawImage(image, screenX, screenY, gp.tileSize, gp.tileSize, null); // Draw player g2.fillRect(screenX + solidArea.x, screenY + solidArea.y, solidArea.width, solidArea.height); // Draw collision rectangle
@TerminallyUnique95
2 жыл бұрын
@@RyiSnow Thanks. I finally figured out.
@mw6092
2 жыл бұрын
Thanks, this was very helpful. I had a similar problem and apparently the solidArea causes trouble if x,y, width and height are not set to numbers but to variables/calculations. I wanted to make it dependent on the tileSize and if, for example, I write solidArea.width = (int) (Math.round(32/48*gp.tileSize)); the collission does not work properly and the collision rectangle is not painted at all. However, with solidArea.width = 42; (for tilesize 64) all works fine.. A bit strange but at least now I know what's the problem :)
@geoartop3363
2 жыл бұрын
@@TerminallyUnique95 hey i am having a similar problem can you tell me how you solved it ?
@TerminallyUnique95
2 жыл бұрын
@@geoartop3363 I had to recheck the code in checkTile until I found what I typed wrong.
@hoancute
2 жыл бұрын
Please turn on subtitles for this video! Thank you so much!
@RyiSnow
2 жыл бұрын
Hmm those subtitles are auto-generated by KZitem so I'm not sure why this video doesn't have one. Maybe a glitch?
@Melvin-14
2 жыл бұрын
@@RyiSnow you have to enable it in your video settings
@RyiSnow
2 жыл бұрын
@@Melvin-14 As far as I know there's no option to enable auto-generated subtitles. You can only manually add subtitles. If you think I'm missing something, let me know how to do it then I'll check it again.
@Melvin-14
2 жыл бұрын
@@RyiSnow yes but can u check ur latest video to see my comment i need help
@tintin5168
2 жыл бұрын
Thank You so much RyiSow
@hijo-0191
Жыл бұрын
Hello, I have a problem where if I try to move, my character gets teleported to the left side of the map
@bluestreak711
Жыл бұрын
7:22 @RyiSnow, Why didn't you use a calculation of gp.tileSize here? It may seem like unnecessary math, but if somebody decides to change the scaling of the game, then this part of the game would not function correctly.
@holmdev
2 жыл бұрын
Good work :)
@marvindietermann9597
2 жыл бұрын
Hey every1, I have a problem: I know someone actually had this problem in the comments before, but the answer didn't help me that much due to me being quite new to coding, but my character keeps getting stuck on collision boxes, with only up being the way out, which then completely stucks the pCharacter in the collision box up top of the pCharacter. Can someone help?
@adrianrazvan17
2 жыл бұрын
same problem, have you found the solution?
@marvindietermann9597
2 жыл бұрын
@@adrianrazvan17 actually yes, i've made seperate boolians for collisionOnUp/Down/Left/Right and coded them in the right places, switch(direction) { case "up": if(collisionOnUp == false) { worldY -= speed; } break; case "down": if(collisionOnDown == false) { worldY += speed; } break; case "left": if(collisionOnLeft == false) { worldX -= speed; } break; case "right": if(collisionOnRight == false) { worldX += speed; } break; } now it works like a charme
@kaitakahashi3167
2 жыл бұрын
Great vid and it really is helping me, but i have found several places where due to collision n the rectangular size make the player stuck in the same position Its like u cant move away from that place. Forever Stuck, was wondering, is there any solution to that?
@FreeStyleCrhymeR
Жыл бұрын
check your collisionChecker. if you put the "break;" statements of switch's in the if statements, it happens. put it outside of if statements.
@Thefoodhistorian0
14 күн бұрын
hey just a question what pixel editing softwear do you use?
@saladstik3158
Жыл бұрын
do you know if there would be a way to do this but keep the ability to move the player diagonal like you could before there was any actual collision detection
@TNHoWalfas
Жыл бұрын
It seems like I have some kind of issue with the collision. My CollisionChecker class is identical to yours but when I run the game, the character is stuck, frozen in place and no animation being played. When I comment out the code to check tile collision in my player class, my character moves again, but can't stop. Terminal output also mentions "java.lang.ArrayIndexOutOfBoundsException: Index 1056 out of bounds for length 50". I have no idea what causing these problems as I followed the collision detection tutorial exactly. EDIT: I figured out at the 20:17 mark I unknowingly put the parenthesis in the wrong place (place the ")" behind ".speed" instead of "gp.tileSize", how I did that I don't know), but the character is constantly moving in one direction unless it collides with a tile...
@happyburger23
Жыл бұрын
@CrippinDoge it should be entity.speed) / gp.tileSize; rather than entity.speed / gp.tileSize);
@elguardallavesdejaal
6 ай бұрын
In this comment I've found salvation, thanks.
@Petronz
Жыл бұрын
I have a question. After i copied that, the collisions are not activied but in walls, water and trees, my character keeps walking but it goes slower and I don't understand why, since we didn't deal with speed in the methods, has anyone come across a similar stuff?
@silenceradieux3590
Жыл бұрын
Same here! Checked out comments section for a solution. I hope someone will help us. 🥶 Update : found this kinda working : case "up": entityTopRow = (entityTopWorldY - entity.speed)/ GamePanel.tileSize; tileNum1 = gp.tileM.mapTileNum[entityLeftCol][entityTopRow]; tileNum2 = gp.tileM.mapTileNum[entityRightCol][entityTopRow]; if (gp.tileM.tile[tileNum1].collision || gp.tileM.tile[tileNum2].collision) { entity.collisionOn = true; entity.speed = 0; } else { entity.collisionOn = false; entity.speed = 4; } break; Do this for each direction.
@davidmako2696
9 ай бұрын
@@silenceradieux3590 lifesaver.
@jojo.-tv
5 ай бұрын
Great Video
@lvdv4j
Жыл бұрын
Hey Ryi, as always your videos are awesome! Because of school I had to set this down for a while but I'm back at it again! This time I want to finish it 😄 I have a question while I'm here on this video. I'm not sure if you're still taking questions, but let's say I have a 32x32 tile, and on this tile I have drawn a treasure chest that only takes up 16x32 of the tile. Is there a way that instead of using the entire TileSize as the collision I could set it in a way that each tile has it's own "temporary collision size" so to speak? I've tried implementing this myself but I can't seem to get it right.
@RyiSnow
Жыл бұрын
You can use the Rectangle class for that, as we did for checking NPCs/Interactive Objects collision :)
@lvdv4j
Жыл бұрын
@@RyiSnow Ah thank you so much! Let me try that and see if I can get it to work 😄
@zeishirou
Жыл бұрын
@@RyiSnow Hey so i followed everything right but when i type collisionOn ut gets an error i dotn know why tho
@diegofiguesevi8355
Жыл бұрын
Hello! Thank you for all these videos, you helped me improve the foundations of my knowledge and in some cases (like in threads) you helped me understand much better everything that at the time I couldn’t understand. But I have a question, in some cases you divide some values by the tileSize and I don’t understand why, could you explain this better to me? The case where I have the most doubt is in the formulas you used at minute 17:00. Why did you do it like that and what does it return? THANK YOU!
@RyiSnow
Жыл бұрын
We divide them by the tile size because we need to get col and row numbers instead of x and y!
@vyzymz
Жыл бұрын
@@RyiSnow for a moment, I also wondered why. but i think, to explain it better, it is because you are looking for a tile in that position, so you divided it by the tileSize. the four (4) numbers you made are like (4) pin points, or simply (4) corners of the collision hitbox, where these pins checks whatever tile they're standing on, whenever you told them to (every frame update, in this project), so that these (4) pins can tell you if it's a solid tile or not. if it's solid, we won't let the player move further to where they want to, otherwise, we will let it happen. to make it more clear, these (4) pins can actually detect 4 different tiles, with the help of tileSize variable, if we let it.
@sukkarakan_haitang
2 жыл бұрын
hellooo.... could I get some help please? my top collision works but the other directions are not working. I've watched a few times but still can't figure out what I did wrong :( Edit: so for some reason my solidArea.height is not working, as a result entity bottom row wasn't either. for now I changed the solidArea.height to width for entityBottomWorldY
@mattb8480
2 жыл бұрын
Thanks so much, very helpful. Any ideas on how I would change the player and collision checker class if I wanted to implement gravity? I used the same tile method for collision and my sprites are in 2D, however I’m not sure how to add gravity and jumping.
@tybrassington1614
Жыл бұрын
Hi Ryi, I got my collision working for the most part, but I've run into an issue when the bottom of the players hitbox is aligned with the bottom of the collision tiles, it will phase through it. I don't run into this issue when the left and the right of the hitbox are aligned with the left or right of the collision tile. Do you happen to know where I went wrong as yours doesn't seem to have that issue.
@tybrassington1614
Жыл бұрын
I'd be happy to supply the code through Github if you need context
@mikeabordo6655
2 жыл бұрын
I'm having a problem with the movement, when I pressed S and then W my character won't go up same with pressing D and A. I can't pressed 2 keys at the same time. but its working on pressing W first and then S and A first and then D
@zhichgaming1466
2 жыл бұрын
For some reason, when I go down, it goes halfway through the tree. I even drawed a black box on the screen as the collision zone and I see that it goes right through the box. This only happens when I go down, not with any other directions. Could you tell me any common mistakes people make so I can check if I made them?
@Nicolaspatti19
Жыл бұрын
i have the same problem, did you solve it ?
@Nicolaspatti19
Жыл бұрын
I find the solution : in the CollisionChecker for case : "down" he made the same mistake than for right so you have to replace the " - " by a " + " on the first line of case down.
@OG-KARMA
2 ай бұрын
Hey I just throw this in here. So collision works fine. Just somehow my character keeps on moving on its own.
@hk-p1027
Ай бұрын
what should i do if theres space between the character and the tile please? Im really stuck on that
@jimmyjakes1823
3 ай бұрын
It's working the way it's supposed to, except when the character moves down and hits the top of an impassable tile. He stops right on the top edge but he cant move left or right before moving back up a little first. Anyone else with this problem? I think I remember this from actual NES games and it's annoying. It's only when he hits an impassable tile moving down though, it's not a problem in any other direction. Raising the bottom of the player hitbox just makes him move down further below the top edge of the impassable tile and then he still can't move left or right without moving back up first. I'd guess either my worldY value is somehow off or it's maybe some integer rounding issue. Any ideas?
@Yamato-gj1li
3 ай бұрын
If your character get stuck on collisions sometimes, check if changed the - to a + in case "down" and case "right" in the CollisionChecker.
@jimmyjakes1823
3 ай бұрын
@@Yamato-gj1li It was just a variable that I missed changing when I copied and pasted. One of the statements still had an 'entityTopRow' variable used in the down case where it was supposed to be 'entityBottomRow'. The effect was subtle enough that I figured it had to be something complicated. It works fine now.
@mastergamer4335
2 жыл бұрын
I tried to optimize it but it dont worked and now i dunno whats wrong but if i hit a wall or somthing solid i cant move at any direction at all.
@mastergamer4335
2 жыл бұрын
Found why.
@wizco4443
Жыл бұрын
whatHapend(?) { iHaveTheSameProblem; }
@milkman6240
3 ай бұрын
Around 11:41 I'm a little confused about what you're doing with those variables. I understand that the actual collision box is a smaller box inside the player box, but what are you trying to with these points? I've watched this video three times and I haven't managed to wrap my head around it.
@jimmyjakes1823
3 ай бұрын
Let's start from 11:41. After you input direction, the player's position is updated. Suppose you are on 23, 22 in the world map and press the up direction which updates the player position to 23, 21. You multiply these tile coordinates for the new position by the tile size 48 to get the pixel coordinates (1104,1008). You then use the offsets in the hitbox to determine the 4 corners that make up the coordinates of the player's collision box on the map. I'm using the actual values here for this situation but don't get hung up on that because they change everytime the player moves: top of the box: 1008+16 bottom of the box: 1008 +48 left of box: 1104+8 right of box: 1104+40 The end result is a smaller box within the 48x48 tile that we use to draw the player sprite, which makes it easier not to bump into impassable tiles. Here's the part I think you're asking about: Since you're hypothetically trying to move up in this example, we check the tiles on the upper left and upper right corner of the player's hitbox which are (1112, 1024) and (1144, 1024). We then divide these coordinates by the tile size to find out what their position is on the 50 x 50 game map in the text file and what type of tiles they are. It's possible for the left upper hitbox to fall in one tile and the right upper side of the hitbox to fall in a different tile so we have to check what the tile is at both coordinates to see whether they're passable, but in this case the entire hitbox falls inside one tile which is 23, 21 and that's a sand tile. If the tiles are impassible the player isn't allowed to move there and you stay at position 23 ,22 or else it is passable and the player moves up to position 23, 21. Is that sort of what you were asking about?
@milkman6240
3 ай бұрын
@@jimmyjakes1823 Thank you for the explanation! I think I'm really beginning to understand things now!
@tidstids
2 жыл бұрын
In checkTile is an error when I write Entity entity, so I need to write Player, it’s that normal?
@RyiSnow
2 жыл бұрын
If player is the only entity that you check collision, writing Player is fine but if you use the method to check other entities such as npcs or monsters (which we will do in later videos), it will cause problems.
@tidstids
2 жыл бұрын
@@RyiSnow I don’t know what I do, but now it’s working!
@tidstids
2 жыл бұрын
In tutorial 14 it start working
@thamiryssmbraga3756
2 жыл бұрын
Hi RyoSnow, I don't know what happened but when I remove the code "worldY -= speed" from update(); and I put it in if(collisionOn == false){ switch(direction){}}, my player is extremely slow, but when I return to the previous location it returns to normal.
@DieterKlingberg
7 ай бұрын
When I collide, my player can't get out of the collision, even though he's no longer colliding, his movements somehow remain on false. I understand how this works, but I can't find a solution
@AlexSilva-zs2ul
4 ай бұрын
I'm wondering how I can draw the collision rectangle on the screen. Can someone help me?
@8NLD8
Жыл бұрын
is this method of detecting collision using the Separating Axis Theorem (SAT)? I've heard that it is used to detect collision in games but I don't know how to implement it and I've never seen it in plain code :S
@1345alen
7 ай бұрын
Hi, can you explain the checkTile section with numbers instead with words, or both. Thank you.
@uday_khare09
5 ай бұрын
My collision is working but the collision rectangle seems to be on the top and a little bit to left
@uday_khare09
5 ай бұрын
And I have the same code
@drstowaters
2 жыл бұрын
Hi, I hope I could get help. When I start the game I can only move on W and when I press A, S or D the animation works but player wont move. But when I move around sometimes my player won't move and sort of get stuck because of som invicible collider. Btw you're touturials are amazing and I've learnt so much!
@cristiano1296
2 жыл бұрын
make sure you put double equal signs in the if statement: if(collisionOn == false)
@drstowaters
2 жыл бұрын
I got it working, the collider was just offset by two tiles for some reason so I just expanded the game screen so it was 16 x 16 tiles instead of 16 x 12 but I can't find the problem why it was that
@LutherCraft222
Жыл бұрын
@@cristiano1296 spent two days trouble shooting and this was my issue thank u so much
@zeishirou
Жыл бұрын
@@LutherCraft222 i still have the issue i dont know how to fix it please help
@spinberry
Жыл бұрын
@@zeishirou did you fix?
@arcxdroid7183
2 жыл бұрын
Hi Ryisnow! Really greatful for your tutorials, am wondering how would I go about making a collision checker between two player models? So far I am currently able to make that the player models can only collide with one another when one is stationary not while moving. Any help would be great!
@RyiSnow
2 жыл бұрын
We've handled collision between characters in Part 14 so you might want to check that video.
@marcell114
Жыл бұрын
first at all thanks for this video. i got a problem somewhere. collision works great but not the character moving non stop, only changing direction when pressing bottoms but keep moving. cant find the problem.
@Lav_not_here
Жыл бұрын
Same, did you find out why? (if so can you show me if thats ok)
@RandomHandle-r2q
2 жыл бұрын
I guess I may have changed something I did not mean to change, because now I can walk through the tree tile. Any suggestions on what I can do?
@alvins5054
Жыл бұрын
If it is only trees it sounds like the mistake is in the TileManager class. Have you checked so that your tree tile has the line tile[5].collision= true; My tree is [5] but it might be different for you.
@cassiew9389
2 жыл бұрын
I am further along in the series but when I try to run my program now I am getting this error : * Exception in thread "Thread-0" java.lang.ArrayIndexOutOfBoundsException: Index 1048 out of bounds for length 50 at Main.CollisionChecker.checkTile(CollisionChecker.java:38) at Entity.Player.update(Player.java:116) at Main.GamePanel.update(GamePanel.java:113) at Main.GamePanel.run(GamePanel.java:93) at java.base/java.lang.Thread.run(Thread.java:833) */ and my mapTileNum = new int[maxWorldCol][maxWorldRow] ----- any ideas what could be causing this?
@RyiSnow
2 жыл бұрын
The program is trying to read the array with the index number 1048 which is way over the array's length ([50]). So my guess is you forgot to convert worldX/Y to Col/Row.
@cassiew9389
2 жыл бұрын
@@RyiSnow sorry to keep bugging you, I just want it to work lol and I really, really appreciated your tutorial. It helped me so much ! this is my public Tile Manager -------
@Melvin-14
2 жыл бұрын
@@RyiSnow what?
@nickrittich1603
2 жыл бұрын
I have a problem with the movement of the player. When I run the program the player doesn't stop moving. This only happens when I change the worldX and worldY to the if(collisionOn == false), any solutions?
@nickrittich1603
2 жыл бұрын
nvm I had to put the, if(keyH.upPressed == true) around the speed in the case
Пікірлер: 321