Java Game Development #16 - Collision Detection

  Рет қаралды 55,179

RealTutsGML

RealTutsGML

Күн бұрын

Пікірлер: 118
@Pindexter77
@Pindexter77 8 жыл бұрын
A follow up video explaining this a bit more would definitely be nice, especially explain the for loop. :)
@jinxpc
@jinxpc 11 жыл бұрын
I cant believe someone Disliked this video, best java Series ever!!!!
@LachezarTsv
@LachezarTsv 5 жыл бұрын
Although it gets kinda confusing, I understand the whole thing, for which I am thankfull, because this really helps me for my project and I believe it will keep helping me in the future
@stonegolemstudios
@stonegolemstudios 9 жыл бұрын
god i spent the last 30 minutes trying to find why boolean for in physics class could not be set to an integer... ohh its because i forgot a tiny very significant i for my entb... anyways keep up the work bud, your tutorials will shape my future programming.
@iq0578
@iq0578 2 жыл бұрын
How can you change what entity is on top?
@saulivanflorestorrescoto9580
@saulivanflorestorrescoto9580 8 жыл бұрын
You make the best tutorial bud, keep it up, and thank you. You really made me understand the concepts!
@JavaCoderz
@JavaCoderz 10 жыл бұрын
Why am I getting a null pointer exception and my game is freeing when I shoot a bullet? I checked my if(Physics.Collision(this, game.eb)) and it is right? I checked the Collision variable, and it is returning false when I don't shoot, but when I do shoot, I think it is returning null. How do I fix this?
@ferasali8228
@ferasali8228 3 жыл бұрын
i think its too late now,but i had the same issue and i literally scanned my code for anything related to collisions and the physics thing,i went to my enemy class and i found a getBounds function that returned the value to null,removed it and its working perfectly fine now
@Robinno12
@Robinno12 11 жыл бұрын
follow up video would be nice :D thanks for doing this series, great work, keep it up
@yPhil
@yPhil 10 жыл бұрын
Better and better... Your mind is a very nice place :)
@m.husainmns3366
@m.husainmns3366 7 жыл бұрын
a follow up video plz and thank's alot we're learning so much
@AsdFG5XQW
@AsdFG5XQW 9 жыл бұрын
I was wondering if you could use the Cross Product as collision detection? it will check if it intersects by returning 0
@ajkdrag
@ajkdrag 8 жыл бұрын
You are passing the game object as the parameter into the bullet class by ( public Bullet( double x, double y, Textures tex, Game game )) . This basically allows the bullet class to have access to the variables and methods of the game class.. Isn't this a bad practice? help needed. I thought the whole point of creating the textures class was so that the bullet, enemy, player would interact with the Textures class for getting the image sprites, and hence the game class would not be accessible to the bullet/enemy/player etc... please clarify. Can't we have another class to do the collision detection thing. or couldn't this be done in a different way?
@valentin2762
@valentin2762 9 жыл бұрын
How would I detect collision between the Bullet and an enemy ship which results in a: c.removeEntity() of the bullet that collides and the ship that is hit? Moreover, how do I correctly utilise the c.removeEntity() method to remove specific objects such as the bullet and the enemy ship that collide?
@kiryonnakira7566
@kiryonnakira7566 5 жыл бұрын
why public x and y when u can make them protected? also why in that caseu let the getters and setters if variables are public ?
@fatihcenesiz9587
@fatihcenesiz9587 5 жыл бұрын
What we need to do when bullet is too fast, its skips enemy and collision is fails ? Please answer
@kosac4414
@kosac4414 7 жыл бұрын
did he make a follow up video explaining about collision cause it was difficult to understand it?
@Stat1onary
@Stat1onary 4 жыл бұрын
Is it possible to get a paste of the code to explore?
@lapnghiepshopee
@lapnghiepshopee 6 жыл бұрын
why dont you use AABB or SAT algorithm ??
@yPhil
@yPhil 10 жыл бұрын
How can I do this integration / load / create / completion / analysis magic in Emacs? (I just have completion and class links)
@ajkdrag
@ajkdrag 8 жыл бұрын
Also you have no method to remove the bullets once they get off screen.... To do that.. we can go to the tick method in the controller class... and add if(entityA.getY() < 0){ removeEntityA(entityA); }
@ejbytes
@ejbytes 8 жыл бұрын
Very cool. I've never used collision detection in Java. I was going to create another game in Flash, but saw this. I haven't been in programming mode in a while... I have a question. Thinking aloud, so bare with me. At 16min, I was thinking about your method of Collision(A, LinkedList B) using a for loop on B (enemies). I wonder if you could instantiate Collision detection in each Entity B as a trait/property of B? What I'm getting at is this. You probably have to put Physics in a ticker yeah? So each ms you have to ask, "is A colliding into loop(all B)". Am I okay still? But if you added a Collition trait and ticker to each object as it's instantiated you wouldn't have to tick a loop of objects, but semi-simultaneously tick each object dynamically as they are created because you'd have added Collision to each object upon instantiation. Would that work? Thinking aloud...
@ejbytes
@ejbytes 8 жыл бұрын
***** My comment was on the inefficiency of using an array and looping through ALL the objects existing. If you listen to his explanation and re-read what I'm stating, you will see that my point was to make the deletion of objects more efficient by usage of dynamically allocation on each object rather than tracking objects in an array; because a loop in constant N of Big(O). Whereas my suggestion is 1:1 on a scale of Big O(1).
@space-nu6hc
@space-nu6hc 8 жыл бұрын
in the collision class the parameters take entityA and a linkedList why is one a linked list and one isn't
@space-nu6hc
@space-nu6hc 8 жыл бұрын
Don't worry, i'm waaaay past this. I learned to do a lot more advanced things. A lot of things involving math, geometry, and even calculus. And that's great because i'm starting at such a young age. So i'm very proud of myself.
@srinicnu5283
@srinicnu5283 3 жыл бұрын
xception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "eb" because "this.game" is null how to fix it!!
@srinicnu5283
@srinicnu5283 3 жыл бұрын
got it fixed without your reply sir
@RealTutsGML
@RealTutsGML 11 жыл бұрын
Thanks! I am glad you like my tutorials. I will be sure to contact you if I ever need anything! Thanks again.
@gameriffy2458
@gameriffy2458 8 жыл бұрын
when i'm shooting, the console said COLLISION DETECTED a LOT of time, and stop when the bullet get out of the screen, help me
@TGamingFull
@TGamingFull 9 жыл бұрын
My player starts at x = 0 and y = 0 and the bullet doesn't come out from the player. I have removed all the x, y in player and bullet class. Please somebody help!
@ejbytes
@ejbytes 8 жыл бұрын
Reading comments... I don't think this is a Q&A. so maybe my question below would be asked to an onlooker instead?
@truthseeker11
@truthseeker11 7 жыл бұрын
I wish I could see this code as a whole. It's so hard to keep track going back and forth and seeing only a portion of the IDE.
@ratsec1756
@ratsec1756 4 жыл бұрын
hehe ide internal dick eruption
@Tokw11
@Tokw11 11 жыл бұрын
I freeze when i shoot due to Exception in thread "Thread-2" java.lang.NullPointerException at game.src.main.Physics.Collision(Physics.java:14) at game.src.main.Ball.tick(Ball.java:29) at game.src.main.Controller.tick(Controller.java:50) at game.src.main.Game.tick(Game.java:162) at game.src.main.Game.run(Game.java:136) at java.lang.Thread.run(Unknown Source) can anyone help?
@ricesoup5115
@ricesoup5115 10 жыл бұрын
I just freeze when I shoot the bullet, It say NullPointerException at if(enta.getBounds().intersects(entb.get(i).getBounds())); Pls help
@xxGrandaSxx
@xxGrandaSxx 10 жыл бұрын
I hope you fixed this already, but for others if they will have that kind of problem, at least I had at the line, in Bullet.java where in method tick() I forgot to change if(Physics.Collision(this, null)) to if(Physics.Collision(this, game.eb))
@quantumcookie64
@quantumcookie64 8 жыл бұрын
Or could we create EntityA and EntityB , both extending Entity ( both ARE entities, right ? ). That might make the code any simpler ?
@sreeramoffcl
@sreeramoffcl 8 жыл бұрын
+Sethu Kumar Its me sreeram ive got where you r learning to design games It can be more simple create an abstract class instead of interface create an enum for id thats it
@konev13thebeast
@konev13thebeast 10 жыл бұрын
I just had my EntityA and EntityB extend Entity
@ctheart8833
@ctheart8833 8 жыл бұрын
hello , is there any other way to detect collision , other than rectangle , if the two sprites are circle then this method reports collision even if the circle comes close to each other without touching ?
@quantumcookie64
@quantumcookie64 8 жыл бұрын
+C The Art If the distance between the centers of the circles is less than ( or equal to ) the sum of their radii , then the circles collide.
@ctheart8833
@ctheart8833 8 жыл бұрын
thanks ,will try
@kamalahmad4566
@kamalahmad4566 8 жыл бұрын
hi Zack I knew this old video and you star other series but I need your help in collision So i add die() method which remove enemy at first it works but when I add more enemies it don't remove enemy that get shot but remove other enemy I know why this happens because we used Linked list when I use remove () it remove frist enemy that added in linked list So how l can remove spceific enemy that get shot So plz I need your help to Finnish my game
@Tokw11
@Tokw11 11 жыл бұрын
Okay and also in the bullet class it says game is not being used but im using constructors such as game.eb .
@bugfacedog44
@bugfacedog44 11 жыл бұрын
Is it possible to just have a boolean value for every entity instead of making two seperate kinds? true = A false = B
@physicsimpossible73
@physicsimpossible73 10 жыл бұрын
What about if you had Entity as the superclass and the Entity A and Entity B extend that and then all the objects extend from either Entity A and Entity B? Would that be OK? I haven't done it, just wondering..
@WaseemSwaileh
@WaseemSwaileh 10 жыл бұрын
Epicnerd73 I am was going to say the same thing ... Actually I have do it .. at run-time the compiler knows exactly what to do .. !!
@physicsimpossible73
@physicsimpossible73 10 жыл бұрын
Waseem Swaileh So it works then?
@WaseemSwaileh
@WaseemSwaileh 10 жыл бұрын
Epicnerd73 it works till I implement Collision ... We need two methods one for get EntityA and EntityB .. and I spend 2 hours trying to figure that out .. but with no luck ... I think we Should encapsulate it with another class and do so check to know the LinkedList to which interface it belongs ... No Idea how .. I know Just that .. We should encapsulate what varies ...
@physicsimpossible73
@physicsimpossible73 10 жыл бұрын
Waseem Swaileh hmm.. Ok, maybe just scrap that idea then.. lol
@WaseemSwaileh
@WaseemSwaileh 10 жыл бұрын
Epicnerd73 Working on it lol ..
@diggerplus4529
@diggerplus4529 9 жыл бұрын
so... my ship starts in the top left corner now and the bullets, when fired, stay up there even if the ship is moving around... did i miss something? watched the video 3 times and my code looks the same as far as i can tell.
@DanFletcher90
@DanFletcher90 9 жыл бұрын
you have to delete "private double x, y;" at the top of your classes. you no longer need them since now you should have: "super(x, y); " inside of your constructor
@diggerplus4529
@diggerplus4529 9 жыл бұрын
Dan Fletcher thanks. it's typical for me to miss the simplest things. appreciate the help. all is good now.
@DanFletcher90
@DanFletcher90 9 жыл бұрын
no problem, I had the same issue. that's how I knew how to fix it :)
@TGamingFull
@TGamingFull 9 жыл бұрын
Dan Fletcher I have the same issue to but I have deleted all the x and y. Please help me
@XceriasNationPyah
@XceriasNationPyah 10 жыл бұрын
I'm 3:44 into the tutorial and when i shoot it the bullets appear for a second at the top left..
@chromdusw6428
@chromdusw6428 10 жыл бұрын
Make sure that you remove the private double x, y at the top of the class
@nashbone472
@nashbone472 8 жыл бұрын
I went through the whole video and every code is written exactly the same, but whenever I ran the game, nothing will load up, bullets, enemies won't show up but the player works. Why is that? Someone please help. Thank you.
@brandonfalconer2090
@brandonfalconer2090 8 жыл бұрын
+DeepVenganceTV Are you getting an error in your console?
@daneczech
@daneczech 11 жыл бұрын
can I download the project somewhere please?
@RealTutsGML
@RealTutsGML 11 жыл бұрын
Yeah, go to the swing forums and check that out. That helped me out sooo much. Good luck!
@hardayasingh2654
@hardayasingh2654 11 жыл бұрын
yup got it...Thankx man... really appreciate your work :D
@bartolj.4502
@bartolj.4502 9 жыл бұрын
when i run the game at 16:44 my enemys dont move, but i can shoot bullets and move player, and few seconds later my enemys start to move and then error occures :( pls somepne help
@darkpaladin.
@darkpaladin. 8 жыл бұрын
+Bartol J. Try checking your tick method in the controller
@bartolj.4502
@bartolj.4502 8 жыл бұрын
Hi, thanks man for trying to help me but this post is like 10 months old and i dont have the code anymore
@darkpaladin.
@darkpaladin. 8 жыл бұрын
I could send you the code if you're interesting
@bartolj.4502
@bartolj.4502 8 жыл бұрын
nah i switched from java to web development just until i get new laptop
@darkpaladin.
@darkpaladin. 8 жыл бұрын
Ok bro, Peace.
@michael_zhou
@michael_zhou 11 жыл бұрын
when I shoot, it displays "collision detected" infinity in the console until I close it. There were no errors displayed, and I watched this video 3 times. I don't know what's wrong. Can anyone help me?
@SteveMorrow8859
@SteveMorrow8859 9 жыл бұрын
Nice stuff. Do you still do game development anymore? I've been following a guy called Indie Developer on another channel. This has led to a reenacted game I created in the 90s. It's a platformer, modeled after the original Pitfall 2 Atari series. Do you know anything about Java sound by the way? Seems to be a complex topic. Thanks.
@RealTutsGML
@RealTutsGML 11 жыл бұрын
Keep watching the series :)
@dje6429
@dje6429 4 жыл бұрын
Hi, awesome tuto, but why do create 2 double attributes in GameObject class to convert them in int inside getBounds() method ? Why not int directly ?
@jay131m
@jay131m 10 жыл бұрын
you explained very well :)
@hardayasingh2654
@hardayasingh2654 11 жыл бұрын
could u please make main menu for this game?
@aleksandarpetrovic106
@aleksandarpetrovic106 11 жыл бұрын
YOU ARE THE BEST !
@neuro5547
@neuro5547 11 жыл бұрын
"We have the inner sex method."
@spillthecode9917
@spillthecode9917 9 жыл бұрын
Yeah, that made me laugh
@BoltReel
@BoltReel 10 жыл бұрын
Well I just wrote a big comment but hit my back button on my mouse :( Basically I just said you could change: for(int i = 0; i < entb.size(); i++) into for(EntityB variableName : entityBArrayList) to further simplify things. I don't know, it's build into Java so just incase you haven't seen it.
@MrJamyvideo
@MrJamyvideo 10 жыл бұрын
yep , good idea thanks man.
@BoltReel
@BoltReel 10 жыл бұрын
allows Some situations it's not the best. But generally its easier to iterate over an ArrayList as a whole like such.
@MrJamyvideo
@MrJamyvideo 10 жыл бұрын
what situations?
@BoltReel
@BoltReel 10 жыл бұрын
allows You'll know when to use either for loop. Using the mentioned for list, you dont have a pointer variable, while using the basic for loop however, you do. -- for(int i=0;i
@MrJamyvideo
@MrJamyvideo 10 жыл бұрын
right yes ahah I also thought about that
@XhubiuXRock
@XhubiuXRock 10 жыл бұрын
Thansk a lot for videos dude!! I'm making my first game and it's running just great I have a question: where the render in Controller comes from? public void render(Graphics g){ for(int i=0;i
@Brax1982
@Brax1982 9 жыл бұрын
VK_Box But there are render methods in the classes that implement the interface EntityA, that is Player and Bullet. At runtime the compiler determines that it's either of those classes. So it's both a Player and an Entity A, thanks to interfaces creating multiple subtype relationship (there is no multiple *inheritance* in Java).
@McUpdated
@McUpdated 11 жыл бұрын
Please do a checkpoint tutorial :D
@zedzedy5941
@zedzedy5941 11 жыл бұрын
hey, how to remove enemy when i hit him with the bullet?
@puqo3809
@puqo3809 5 жыл бұрын
lmao call the remove method maybe? jeez sometimes its better to use your own brain
@adamkubala9827
@adamkubala9827 11 жыл бұрын
Make GM contest plz....
@RealTutsGML
@RealTutsGML 11 жыл бұрын
I am going to do one, I am in the process of making a game for a client and when I am done with that I will use there art to make the series. (The game I am making is a fighting game)
@CPIHOrRbI3
@CPIHOrRbI3 11 жыл бұрын
I'm stupid. how to remove the bullet, along with the enemy? I can just remove enemy. I changed code in Physics to: if(enta.getBounds().intersects(entb.get(i).getBounds())){ entb.remove(i); Game.enemy_killed++; return true; }
@Brax1982
@Brax1982 9 жыл бұрын
Noooo, the damn Game parameter is back! Well, off the top of my head I have no idea how to avoid it. And why do you write "Collision" instead of "collision"? Capitalized method names...gah. It's probably like that "block" parameter. Something you got used to doing for some reason. If you still remember why, I would love to know where that habit is from.
@iliasilisparrow
@iliasilisparrow 11 жыл бұрын
Thanks man !
@srinicnu5283
@srinicnu5283 3 жыл бұрын
what is your age
@RealTutsGML
@RealTutsGML 11 жыл бұрын
will get into that when I reach collision detection with the player to enemy and bullet to enemy.
@AnimePFP
@AnimePFP 11 жыл бұрын
Please do an advanced fighter game tutorial for game maker? You never even respond to any of my comments.
@taylorkohls5268
@taylorkohls5268 9 жыл бұрын
So now the game freezes whenever I shoot
@3rdlastsurvivor
@3rdlastsurvivor 8 жыл бұрын
+Taylor Kohls did you find a fix to this?
@3rdlastsurvivor
@3rdlastsurvivor 8 жыл бұрын
+Taylor Kohls did you find a fix to this?
@balajia3970
@balajia3970 7 жыл бұрын
Awesome!
@matthewnotreal1118
@matthewnotreal1118 9 жыл бұрын
Hmm. This doesnt work. It always returns true.
@shatley123
@shatley123 11 жыл бұрын
Java tutorials > gamemaker tutorials
@CPIHOrRbI3
@CPIHOrRbI3 11 жыл бұрын
I already did :). if anyone need. I add new method, similar like Collision method: In Physics: public static boolean Collisions(LinkedList EntityA enta, LinkedList EntityB entb){ for(int i = 0; i< entb.size(); i++){ for(int k = 0; k< enta.size(); k++){ if(enta.get(k).getBounds().intersects(entb.get(i).getBounds())){ enta.remove(k); entb.remove(i); return true; }}}return false;} // In Bullet similar but: private Game game; if(Physics.Collisions(game.ea, game.eb))... Translated by Google :)
@kcreview4937
@kcreview4937 4 жыл бұрын
not very clean code, smelly, and not scaleable. Low cohesion and hard to maintain. Just about impossible to add new features as well once the project gets to a certain size
@rmdir
@rmdir 4 жыл бұрын
Somethings rotten in Denmark with this game....
@hex1101
@hex1101 5 жыл бұрын
yay collison detected (mine just says boom)
@speedkung9925
@speedkung9925 7 жыл бұрын
AWWWW GameObject is weirdddd!!!! It not render in right place ._.
@speedkung9925
@speedkung9925 7 жыл бұрын
Oh.. yeah... finally I fixed it thank you for helpb :)
@betterthansteve5641
@betterthansteve5641 3 жыл бұрын
What was the solution ?
@speedkung9925
@speedkung9925 3 жыл бұрын
@@betterthansteve5641 If you asked me 4 years earlier i could probably tell you
@ratsec1756
@ratsec1756 4 жыл бұрын
YAYAYAYAYAY
@zbigniew463
@zbigniew463 5 жыл бұрын
You have no idea how it works. You just try to work something without resting. Learn how to do it first bottom-up, then first top-buttom. That what you present is good for someone who know nothing about programming
Java Game Development #17 - Animations
9:24
RealTutsGML
Рет қаралды 25 М.
Collision detection in Java - The basics.
6:19
MrJavaHelp
Рет қаралды 67 М.
How Strong is Tin Foil? 💪
00:25
Brianna
Рет қаралды 72 МЛН
22 - Collision Detection! - New Beginner 2D Game Programming
19:12
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 727 М.
A New Beginning - Episode #01 - Java Game Development Tutorial
27:39
Kaarin Gaming
Рет қаралды 296 М.
Please Stop Making These JavaScript Mistakes
14:04
Conner Ardman
Рет қаралды 18 М.
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН
Learning C# In A Week... Otherwise I Fail University
9:04
Where is Rust being used?
11:46
Let's Get Rusty
Рет қаралды 121 М.
C#'s Best features you might not be using
31:20
dotnet
Рет қаралды 17 М.
Java Programming: Let's Build a Game #1
20:29
RealTutsGML
Рет қаралды 1,7 МЛН
Making Games Is Easier With The Expression Builder
5:33
GDevelop
Рет қаралды 2,5 М.