After one hour of tears and headsmahes i found this video and the title saved my life... i didnt use 2D... Even tho i used 2D components hundrets of times in the past... Its 4 AM now and i can peacefully go to sleep, tyvm.
@@RomainDelmaire I'm sorry if my comment meant shaming. it was not the intention. I soon realized how important Physics and Maths are to Game development.
@@nathanmcconnell9991 In physics, you learn about Rigidbody. Some of the requirements when you go to uni to learn game programing is Physics and maths.
I needed this so badly for a long time. I am so happy to finally discover your channel as it is truly inspiring work :) Thank you for everything you have contributed to the unity community Code Monkey!
This is a really good tutorial, because it does not only show one way to do something and is over, but it covers several ways how to do and how not to do the topic the video is about. This makes things easier to get put together inside the brain of someone watching. Good work.
I made a project and the walls were not working, then I permanently deleted the project and made a new one and I felt like to quit on this idea, but then you cam and saved me from rewriting 567 lines of code. love u Thanks :D
Some call him The Next Brackeys Others call him a Legend I call him "The man that the saved me from starting a new project by ACTUALLY making a good Tutorial about Collisions "
Thank you so much, I have been working on my first game ever. Even though it is a 3d game this finally got a object to detect the thing- THIS SAVED ME SO MANY HOURS.
I was looking to learn more about collisions, but what ended up really helping me on the video was discovering the Rigidboy2D.MovePosition function, which made me found out the solution to my player movement. I was doing it using the transform before, which wasn't working properly when moving towards terrain
Awesome video ,I really understand the concepts of collisions better now. Can you also make more on 3d development that would be really helpful Thanks,love your videos
Hay code monkey bro i frickin love you omg you saved me actully i needed the function on collision exit and i was not knowing that this finction even exists bro i was almost going to quit my game but you saved it bro i am sooo frickin glad i found your vid
Thank you so much! I have been trying to make a title screen, and the trigger wasn't working. I found this video 30 minutes after midnight, and it allowed me to go to bed.
Man, I had the same problem, I was trying to play an animation trigger with just the collider, when I tried this, I almost make you a coding religion, haha. Thanks man.
OnVoidStay2D That line of code saved me! I was trying to make an attack for my character, it is a sword slash, due the circunstances i had to use the Polygon collider as a trigger, then it was simple, i would press the button, if it detected an object with the enemy tag in range it would play the damage animation while removing a life point. The problem was: i didn´t read the whole Unity manual so the only OnTrigger/OnCollider i knew was OnTriggerEnter, from here you can guess the problem. Really stupid of my part....
Hello, great video but i didn't manage to solve my problem, was wondering if i could have some of your time. Currently, my player has the following components: transform, renderer, animator (custom script), rigid body 2D, box collider 2D as well as a movement script. The tilemap i want the player to interact with has: tilemap, a renderer, tilemap collider 2D. All these components have their default settings (eg: the player is a dynamic object not kinematic), and my problem is very odd, my player can walk across the floor, will 'hit' the ceiling and not go any higher, but for some reason can pass through the tiles left to right; so my problem is that the x axis collisions are working (as i can walk on them), but my y axis doesn't seem to (as my player can pass through them when walking left to right). Thank you for any help, James
Thanks for this, I needed this tutorial today, I was doing colliders and triggers were set up perfectly, the only difference was my Player never had a rigidbody, so weird that it needs that.
Really cool video, but I have a problem. If I want one object to collide with something and also to be trigger to something, how can I achieve this? (for example a projectile that bounces off the walls but effects the player as trigger)
Love your videos. They help me a lot. I'm having a problem now and I dont know how to find a solution. I need to detect areas in a sphere with mouse click, like a globe. Do you know how I can do that?
@@CodeMonkeyUnity Oh nice! I'll check that. Thank you! So what I need to do is include a collider for each region I want to detect on the sphere and put all as sphere children?
@@stakes_z Yes, if you have your globe with separate mesh parts that you want to select, just add a Mesh collider to each part. Then when when you click you can just do a raycast if you want to test a single point ua-cam.com/video/0jTPKz3ga4w/v-deo.html Or use Physics.OverlapSphere if you want to test with a bit of range
Hi. I would just like to say that it worked. I took meshes for each region of the map, put a mesh collider on each one and used your tutorial on clicking 3d objects as a base. Thank you very much! :D @Code Monkey
ok I answered my question, but the problem still remains, when I put my character from Kinematic to Dynamic on the rigidbody2d, it starts to fall horizontally, and my up button on the joystick doesnt work, like gravity is against it... i set the mass to 1, but still falls, i copied everything i could on your video, but still keeps falling, what else should i check for?
Hi! thanks for the vid, its awesome and really helped me on undersatding colissions better! i have a question, if i want a multiple triggers to cause a different events how can i do that?
So for some reason, none of the triggers or collision code work. Even when there there a rigidbody. it just doesn't detect that the player and the object is touching. like the player cant go through the item but it not sensing that theyre touching
uhmm, i have a polygon collider. I'm trying on triggerstay2D event for this. But uh If i wait with dummy mode ( so doing nothing ) in my polygon collider it's working for 2 seconds. But after debug.log is not logging while when i out from dummy mode. Why it's stopping working .? And how can i do like your heal circle in this video.
Hello. I am trying to detect on trigger condition with prefabs. But the problem is it is detecting the collision with only the first prefab out of the spawning prefabs. How to rectify this?
I'm using ontriggerenter 2 and ontriggerexit2d to check if my character is inside a cave. but since my character's collider is smaller than the collider of the cave, the oncolliderexit2d command works as soon as I enter the door as if I went out of the cave, how can I fix this?
Happy for everyone that makes their game works. Unfortunately, mine is now working. I have a rigidbody2d, boxcollider2d for my player, and a gameobject which has a boxcollider for the trigger. And also in my script, I used OnTriggerEnter2d. But it still doesn't work. Send help please.
Hi! Please help me! How can I determine the coordinates of the vertices of the Box Collider? If the object's rotation is not (0, 0, 0), then collider.bounds doesn't help.
Hi, i get the same issue and i add a rigidbody to the two object (put on static on the trigger object and dynamic to the player) and it works, hope it was useful
thank you for the tutorial, do I need to use RigidBody2d to make it stop against walls? right now i am using a joystick prefab, and in the code using: player.transform.position, and I set an object, just a black cube, with only box collider 2d, and the player still goes through it... so again, is it because I am using transform.position instead of Rigidbody2d? I set everything you did at the 5:51 video mark.... but not working.
The rigidbody by itself has no shape, the shape is on the collider. So just a rigidbody will move through walls If you manually set the transform.posiiton then you're overriding the rigidbody logic (unless you make it kinematic but then you have to handle collisions yourself)
Great video on a topic i've been working on; question on something you didn't cover. How can i make my pickup/trigger (in your case a health potion) only interact with 'player'? ie if you push a rock into the health potion the rock would activate the trigger. I've tried a lot of combinations of playertag = 'player' (not written like that ofc) but still can't get it to only trigger when the player character enters (i have a lot of debris flying around). Thanks!
In the script where you're testing for the collision you have a reference to that object and whatever other object collided with it. In terms of identifying there are many ways you can do it, if the player has a Player class attached to it then doing (otherCollider.GetComponent() != null) would be the simplest.
After one hour of tears and headsmahes i found this video and the title saved my life... i didnt use 2D... Even tho i used 2D components hundrets of times in the past... Its 4 AM now and i can peacefully go to sleep, tyvm.
aaand you just saved me
@@data_corrupted i think you might need to fix your data.
I almost quit my first game after 3 days of tweaking the code, turns out it only needed a rigidbody, damn, I owe you one a big thanks
If you learnt Physics and mathematics well in High school, You will know the engine better.
@@junejuly532 Don't shame someone on what they didn't learn. Encourage them for what they are learning.
@@RomainDelmaire I'm sorry if my comment meant shaming. it was not the intention. I soon realized how important Physics and Maths are to Game development.
@@junejuly532 Knowing physics and knowing you needed a RigidBody in Unity are not the same thing.
@@nathanmcconnell9991 In physics, you learn about Rigidbody. Some of the requirements when you go to uni to learn game programing is Physics and maths.
I needed this so badly for a long time. I am so happy to finally discover your channel as it is truly inspiring work :) Thank you for everything you have contributed to the unity community Code Monkey!
I'm glad the video helped you! Thanks!
This is a really good tutorial, because it does not only show one way to do something and is over, but it covers several ways how to do and how not to do the topic the video is about. This makes things easier to get put together inside the brain of someone watching. Good work.
Thanks! Glad you liked it!
My man, I spent like 45 minutes trying to figure this out. Was missing the all important 2D at the end. Thanks much!
I searched on many videos and websites, and now I finally found how to make the player not pass through the walls
,Thank you!
I made a project and the walls were not working, then I permanently deleted the project and made a new one and I felt like to quit on this idea, but then you cam and saved me from rewriting 567 lines of code.
love u
Thanks :D
Some call him The Next Brackeys
Others call him a Legend
I call him "The man that the saved me from starting a new project by ACTUALLY making a good Tutorial about Collisions "
Thank you so much, I have been working on my first game ever. Even though it is a 3d game this finally got a object to detect the thing- THIS SAVED ME SO MANY HOURS.
I'm glad the video helped!
Your channel is very good, your English is very clear and the speed that you speak is very nice, helpful for those non-natives
2 years later and still saving lives, great tutorial saved me a lot of time :)
I was going mad trying to get OnTriggerEnter to work, you're awesome!
I see a fellow Bread, alliance??
I was looking to learn more about collisions, but what ended up really helping me on the video was discovering the Rigidboy2D.MovePosition function, which made me found out the solution to my player movement. I was doing it using the transform before, which wasn't working properly when moving towards terrain
OHH! THANK YOU!
my mistake is that I was actually using OnCollisionEnter insted of OnTriggerEnter! never notice this till now =-=
mine is OntriggerEnter instead of OnTriggerEnter... been spending hours for a spelling mistake T _ T
@@iamyourfather6941 haha! that's C# for yah
very clear explanation, thank you so much, now I can fully understand differences between these kind of collisions!
Thank you :) After 5 hours of finding the problem I've finally fixed it
I f***ing love you man, you have saved me
I am a simple man, I see Code Monkey and I like it.
Aynen :)
Man you stole my line, :) But yes we both are simple men for sure
@@iDigvijaysinhG Sharing is caring, right?
Thank you for the help. I was struggling a lot to make the collider work but now it works. I am new to unity and C# and you are of great help.
Thank you, my game really coming along, I just added split screen multiplayer
I was going crazy... could not get a state change inside the trigger. Watching the debugs you used solved my problem lol!! Many thanks!!
Awesome video ,I really understand the concepts of collisions better now.
Can you also make more on 3d development that would be really helpful
Thanks,love your videos
Found you through the ads and really liking your videos. Subscribed
Glad you like the videos!
Hay code monkey bro i frickin love you omg you saved me actully i needed the function on collision exit and i was not knowing that this finction even exists bro i was almost going to quit my game but you saved it bro i am sooo frickin glad i found your vid
Thanks bro it was helpful... First I thought my script was wrong and deleted it and wrote again and again deleted... But now it's working
Thank you so much! I have been trying to make a title screen, and the trigger wasn't working. I found this video 30 minutes after midnight, and it allowed me to go to bed.
bruv I was giving up making a (TOP DOWN DODGER) game because of the rigidbody :)
I just subbed to the game dev god
Thanks Code Monkey You Really Helped Me A Lot!
THANK YOU turns out i just needed 2D at the end. thanks lots
Thank you for this video, I was stuck wondering why my collisions wouldn't work.
Helped me a lot! Looking forward for your game on steam!
Thank you so much!!! I was finding the way that can solve the problem which is first explained in your video! Thank you!!
o m g, i freaking love you, i have been looking for solution for so long and no one says about rigidbody2d XDDD
You are actually so cool. Thank you so much for all of these amazing tutorials you are producing. :)
THANKSSSSSSSSSSSSSS MAN YOU JUST SAVE ME, I WAS 6h ON THIS
if I had 3 wishes, my first wish will that you will have a million subscribers
Thank you!
THANK YOU!! It got stuck at this problem for over an hour.
Bro thank you, i so confused when i making, but you explain this. Thank You
This was very helpful. You're the 🐐
Amazing, solved my problem super quickly. Love you!
I'm glad thte video helped you!
Your teaching ability is quite exceptional 👌👌👌👌👌👌👌
I really love it💖💖💖💖💖
Thanks as always uploading Such information viedo 🙏🙏🙏🙏🙏🙏
Thanks very much! This tip saved my work, congratulations!
This was really really helpful, thank you very much!!
Nice! I was using a 3d collider for 2d game, thanks for helping! :)
Man, I had the same problem, I was trying to play an animation trigger with just the collider, when I tried this, I almost make you a coding religion, haha.
Thanks man.
OnVoidStay2D
That line of code saved me! I was trying to make an attack for my character, it is a sword slash, due the circunstances i had to use the Polygon collider as a trigger, then it was simple, i would press the button, if it detected an object with the enemy tag in range it would play the damage animation while removing a life point. The problem was: i didn´t read the whole Unity manual so the only OnTrigger/OnCollider i knew was OnTriggerEnter, from here you can guess the problem. Really stupid of my part....
Hello, great video but i didn't manage to solve my problem, was wondering if i could have some of your time.
Currently, my player has the following components: transform, renderer, animator (custom script), rigid body 2D, box collider 2D as well as a movement script. The tilemap i want the player to interact with has: tilemap, a renderer, tilemap collider 2D. All these components have their default settings (eg: the player is a dynamic object not kinematic), and my problem is very odd, my player can walk across the floor, will 'hit' the ceiling and not go any higher, but for some reason can pass through the tiles left to right; so my problem is that the x axis collisions are working (as i can walk on them), but my y axis doesn't seem to (as my player can pass through them when walking left to right).
Thank you for any help,
James
Thanks for this, I needed this tutorial today, I was doing colliders and triggers were set up perfectly, the only difference was my Player never had a rigidbody, so weird that it needs that.
Life saver always, Thanks Hugo :)
THANK GOD IT WORKS YOU ARE A GENIUS
I'm glad the video helped!
Amazing as always.
Code Monkey saves the day again! woop thx man!
Very helpful and great explanation, thanks man
Ты легенда. Спасибо за детство
Thank you so much for this video !! Really helpful!!
I'm glad it helped you!
This is very helpful, I Subscribed :)
you save me again! thanks from brazil
Nice!
You saved my team
I'm glad the video helped you!
you make my day ... thank you !!!
Love your Tutorials . Awesome and simple explanations
Keep up the great work buddy. I wish you success and more of it.
the trigger still doesn't respond in the debug code for me
Me too :/
Same unity broke ass engine
Dude I had everything right except I was using OnTriggerEnter instead of OnTriggerEnter2D! Thanks!
cheers! my issue was using OnTriggerEnter instead of OnTriggerEnter2D :)
Great video, thanks . I wasnt getting any output from the OnTriggerExit function due to I was testing collision vs collsion2d
Really cool video, but I have a problem. If I want one object to collide with something and also to be trigger to something, how can I achieve this? (for example a projectile that bounces off the walls but effects the player as trigger)
+
Love your videos. They help me a lot.
I'm having a problem now and I dont know how to find a solution. I need to detect areas in a sphere with mouse click, like a globe. Do you know how I can do that?
You can use Physics.OverlapSphere(); or Physics2D.OverlapCircle();
It will find all objects will colliders within range
@@CodeMonkeyUnity Oh nice! I'll check that. Thank you! So what I need to do is include a collider for each region I want to detect on the sphere and put all as sphere children?
@@stakes_z Yes, if you have your globe with separate mesh parts that you want to select, just add a Mesh collider to each part. Then when when you click you can just do a raycast if you want to test a single point ua-cam.com/video/0jTPKz3ga4w/v-deo.html
Or use Physics.OverlapSphere if you want to test with a bit of range
@@CodeMonkeyUnity Awesome! Thank you so much! I'll create my globe with multiple meshes and try it. Thank you
Hi. I would just like to say that it worked. I took meshes for each region of the map, put a mesh collider on each one and used your tutorial on clicking 3d objects as a base. Thank you very much! :D @Code Monkey
Nice, I found the issue with mine being that I was using the 3d collision and not 2d! Only figured out when I copied your code out by hand lol
Yup I've made that mistake myself several times when I was a beginner
Great work and you're so excellent! Helped me a lot.
Thank you for this video!
ok I answered my question, but the problem still remains, when I put my character from Kinematic to Dynamic on the rigidbody2d, it starts to fall horizontally, and my up button on the joystick doesnt work, like gravity is against it... i set the mass to 1, but still falls, i copied everything i could on your video, but still keeps falling, what else should i check for?
Great tutorial! Thank you so much!
Hi! thanks for the vid, its awesome and really helped me on undersatding colissions better! i have a question, if i want a multiple triggers to cause a different events how can i do that?
Make multiple separate game objects each with its own trigger and script
you literlly safed my life
So helpful, thank you as always!
So for some reason, none of the triggers or collision code work. Even when there there a rigidbody. it just doesn't detect that the player and the object is touching. like the player cant go through the item but it not sensing that theyre touching
your typing speed is faster than light omg
increible Thanks CodeMonkey:D
uhmm, i have a polygon collider. I'm trying on triggerstay2D event for this. But uh If i wait with dummy mode ( so doing nothing ) in my polygon collider it's working for 2 seconds. But after debug.log is not logging while when i out from dummy mode. Why it's stopping working .? And how can i do like your heal circle in this video.
I always forget "2D" at the end of the method name! Thanks!!!
I WAS SEARCHING FOR THIS FOR HOURS YOU SAVED MY COMPUTER FROM ME XDD
I'm glad you found it helpful!
i have a 2D Player Object with a Child 2D Object but i want to use the Child Object as Collision detector but how?
thank u man, u solved my problem
I'm glad the video helped! Thanks!
Thank you! You saved my life!
Hello. I am trying to detect on trigger condition with prefabs. But the problem is it is detecting the collision with only the first prefab out of the spawning prefabs. How to rectify this?
very helpful. just one problem that light bright coding screen is killing my eyes.
Sorry but dark mode burns my eyes
I'm using ontriggerenter 2 and ontriggerexit2d to check if my character is inside a cave. but since my character's collider is smaller than the collider of the cave, the oncolliderexit2d command works as soon as I enter the door as if I went out of the cave, how can I fix this?
well i have rigidbody and doesn't work. I made lots of functions in the scene with triggerenter and they work...the collision layer are all checked
Dan SV I have the same problem
hey there great video, im having a problem with my player starting to rotate when i collide with my chest
On the Rigidbody you can set it to fix rotation
Nice I can use that on my bullet & it won't stick to the wall or I can not & make it stick to the wall TY.
Very informative thanks
Happy for everyone that makes their game works. Unfortunately, mine is now working. I have a rigidbody2d, boxcollider2d for my player, and a gameobject which has a boxcollider for the trigger. And also in my script, I used OnTriggerEnter2d. But it still doesn't work. Send help please.
Your gameobject needs a BoxCollider2D, not BoxCollider
Thanks code monkey for helping us..
OMG thanks for this video my only problem was the little "2D" you need to add after OnTriggerEnter and the collider
Same here
Shitttt i didn't realised there was a 2d trigger tooo thank u mannnn 😭 u saved mee i didn't even noticed in video damnnn thnxxxx
Hi! Please help me! How can I determine the coordinates of the vertices of the Box Collider? If the object's rotation is not (0, 0, 0), then collider.bounds doesn't help.
For some reason it's still not working for me, any ideas what could be the possible reasons?
Hi, i get the same issue and i add a rigidbody to the two object (put on static on the trigger object and dynamic to the player) and it works, hope it was useful
thank you for the tutorial, do I need to use RigidBody2d to make it stop against walls? right now i am using a joystick prefab, and in the code using: player.transform.position, and I set an object, just a black cube, with only box collider 2d, and the player still goes through it... so again, is it because I am using transform.position instead of Rigidbody2d? I set everything you did at the 5:51 video mark.... but not working.
The rigidbody by itself has no shape, the shape is on the collider. So just a rigidbody will move through walls
If you manually set the transform.posiiton then you're overriding the rigidbody logic (unless you make it kinematic but then you have to handle collisions yourself)
Thank you King
Great video on a topic i've been working on; question on something you didn't cover.
How can i make my pickup/trigger (in your case a health potion) only interact with 'player'? ie if you push a rock into the health potion the rock would activate the trigger.
I've tried a lot of combinations of playertag = 'player' (not written like that ofc) but still can't get it to only trigger when the player character enters (i have a lot of debris flying around).
Thanks!
In the script where you're testing for the collision you have a reference to that object and whatever other object collided with it. In terms of identifying there are many ways you can do it, if the player has a Player class attached to it then doing (otherCollider.GetComponent() != null) would be the simplest.
@@CodeMonkeyUnity Thanks! I'll give that a shot!
Thanks !