Collisions and Triggers ("OnTriggerEnter not working!" - Unity Tutorial)

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии • 434

  • @olotolow
    @olotolow 3 года назад +49

    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.

    • @data_corrupted
      @data_corrupted 3 года назад

      aaand you just saved me

    • @foxfirefive
      @foxfirefive 3 года назад

      @@data_corrupted i think you might need to fix your data.

  • @friedrichhieronymus8786
    @friedrichhieronymus8786 4 года назад +50

    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

    • @junejuly532
      @junejuly532 4 года назад

      If you learnt Physics and mathematics well in High school, You will know the engine better.

    • @RomainDelmaire
      @RomainDelmaire 4 года назад +9

      @@junejuly532 Don't shame someone on what they didn't learn. Encourage them for what they are learning.

    • @junejuly532
      @junejuly532 4 года назад +4

      @@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
      @nathanmcconnell9991 4 года назад +6

      @@junejuly532 Knowing physics and knowing you needed a RigidBody in Unity are not the same thing.

    • @junejuly532
      @junejuly532 4 года назад +1

      @@nathanmcconnell9991 In physics, you learn about Rigidbody. Some of the requirements when you go to uni to learn game programing is Physics and maths.

  • @abdessamadcherrat5275
    @abdessamadcherrat5275 2 года назад +11

    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 "

  • @freemoncodes
    @freemoncodes Год назад +1

    My man, I spent like 45 minutes trying to figure this out. Was missing the all important 2D at the end. Thanks much!

  • @Kewie1337
    @Kewie1337 2 года назад +22

    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!

  • @joaocarvalho7189
    @joaocarvalho7189 4 года назад +1

    I searched on many videos and websites, and now I finally found how to make the player not pass through the walls
    ,Thank you!

  • @ZeroIdeas9000
    @ZeroIdeas9000 11 месяцев назад +1

    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.

  • @_decoded_
    @_decoded_ Месяц назад

    OH MY GOD 2 HOURS OF PAIN BECAUSE I DIDNT HAVE A RIGID BODY.
    In all seriousness this tutorial was a life saver, sending love man ❤

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Месяц назад +1

      heh I'm glad the video helped you! Thanks!

  • @hardgames4104
    @hardgames4104 5 лет назад +7

    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.

  • @croeusjawad9744
    @croeusjawad9744 3 года назад

    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

  • @canerozdemir4195
    @canerozdemir4195 5 лет назад +15

    I am a simple man, I see Code Monkey and I like it.

  • @loklo
    @loklo 3 года назад

    2 years later and still saving lives, great tutorial saved me a lot of time :)

  • @wiltongarcia4864
    @wiltongarcia4864 4 года назад +1

    Your channel is very good, your English is very clear and the speed that you speak is very nice, helpful for those non-natives

  • @breadofgodd
    @breadofgodd 4 года назад +2

    I was going mad trying to get OnTriggerEnter to work, you're awesome!

    • @elbreadroh
      @elbreadroh 4 года назад +1

      I see a fellow Bread, alliance??

  • @swedstonetv322
    @swedstonetv322 2 года назад +1

    Thank you :) After 5 hours of finding the problem I've finally fixed it

  • @Phalanx3351
    @Phalanx3351 4 года назад +4

    OHH! THANK YOU!
    my mistake is that I was actually using OnCollisionEnter insted of OnTriggerEnter! never notice this till now =-=

    • @iamyourfather6941
      @iamyourfather6941 4 года назад +1

      mine is OntriggerEnter instead of OnTriggerEnter... been spending hours for a spelling mistake T _ T

    • @Phalanx3351
      @Phalanx3351 4 года назад +1

      @@iamyourfather6941 haha! that's C# for yah

  • @diegocarrionportilla8718
    @diegocarrionportilla8718 3 года назад +2

    I f***ing love you man, you have saved me

  • @AraragiAriel
    @AraragiAriel 2 года назад +2

    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

  • @CodesnippetBiz
    @CodesnippetBiz 4 года назад +5

    very clear explanation, thank you so much, now I can fully understand differences between these kind of collisions!

  • @noether9447
    @noether9447 5 лет назад +1

    Found you through the ads and really liking your videos. Subscribed

  • @illuminith6405
    @illuminith6405 3 года назад

    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.

  • @Gurseerat_Singh
    @Gurseerat_Singh 4 года назад +1

    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

  • @swepo5719
    @swepo5719 Год назад

    o m g, i freaking love you, i have been looking for solution for so long and no one says about rigidbody2d XDDD

  • @abrahamliz2559
    @abrahamliz2559 4 года назад

    I was going crazy... could not get a state change inside the trigger. Watching the debugs you used solved my problem lol!! Many thanks!!

  • @utilityy
    @utilityy 4 года назад +3

    You are actually so cool. Thank you so much for all of these amazing tutorials you are producing. :)

  • @subzero4787
    @subzero4787 4 года назад

    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

  • @IsaacJairi
    @IsaacJairi 4 года назад +2

    THANKSSSSSSSSSSSSSS MAN YOU JUST SAVE ME, I WAS 6h ON THIS

  • @aminmk697
    @aminmk697 4 года назад

    bruv I was giving up making a (TOP DOWN DODGER) game because of the rigidbody :)
    I just subbed to the game dev god

  • @thefakejonfischer
    @thefakejonfischer 4 года назад

    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.

  • @Motyy
    @Motyy 10 месяцев назад

    THANK GOD IT WORKS YOU ARE A GENIUS

  • @alvinmanoj70
    @alvinmanoj70 3 года назад

    if I had 3 wishes, my first wish will that you will have a million subscribers

  • @DridgeDEU
    @DridgeDEU 7 месяцев назад

    Amazing, solved my problem super quickly. Love you!

  • @pholux5647
    @pholux5647 2 года назад +1

    Thanks Code Monkey You Really Helped Me A Lot!

  • @DARK_AMBIGUOUS
    @DARK_AMBIGUOUS 3 года назад +2

    Thank you, my game really coming along, I just added split screen multiplayer

  • @TechGuyDane
    @TechGuyDane 2 года назад

    This was very helpful. You're the 🐐

  • @anirbankarmakar2037
    @anirbankarmakar2037 5 лет назад +15

    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

  • @bbuddyyeapp3557
    @bbuddyyeapp3557 3 года назад

    Thank you so much!!! I was finding the way that can solve the problem which is first explained in your video! Thank you!!

  • @namenight7158
    @namenight7158 4 года назад +1

    Helped me a lot! Looking forward for your game on steam!

  • @samuellucaslimasoares9010
    @samuellucaslimasoares9010 2 года назад

    Thanks very much! This tip saved my work, congratulations!

  • @ProfessorNova42
    @ProfessorNova42 4 года назад

    THANK YOU!! It got stuck at this problem for over an hour.

  • @serialchiller9183
    @serialchiller9183 5 лет назад +4

    Amazing as always.

  • @Ranoluq
    @Ranoluq Год назад

    Bro thank you, i so confused when i making, but you explain this. Thank You

  • @gameovercom
    @gameovercom 4 года назад +1

    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.

  • @redfoxlightning
    @redfoxlightning 3 года назад

    THANK YOU turns out i just needed 2D at the end. thanks lots

  • @areion819
    @areion819 3 года назад

    Thank you for this video, I was stuck wondering why my collisions wouldn't work.

  • @harneetsingh9420
    @harneetsingh9420 Год назад

    Life saver always, Thanks Hugo :)

  • @dhankumari7290
    @dhankumari7290 5 лет назад +1

    Your teaching ability is quite exceptional 👌👌👌👌👌👌👌
    I really love it💖💖💖💖💖
    Thanks as always uploading Such information viedo 🙏🙏🙏🙏🙏🙏

  • @nathaliaperes1392
    @nathaliaperes1392 4 года назад +2

    This was really really helpful, thank you very much!!

  • @rodrigogriner9904
    @rodrigogriner9904 Год назад

    Nice!
    You saved my team

  • @dwlg
    @dwlg 3 года назад

    Code Monkey saves the day again! woop thx man!

  • @crazyone3494
    @crazyone3494 Год назад

    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....

  • @footballgirl48
    @footballgirl48 3 месяца назад

    Thank you so much for this video !! Really helpful!!

  • @neozoid7009
    @neozoid7009 2 года назад

    Love your Tutorials . Awesome and simple explanations

  • @KhaledHakim
    @KhaledHakim 4 года назад

    Keep up the great work buddy. I wish you success and more of it.

  • @Excess-qn7qh
    @Excess-qn7qh 2 года назад

    you make my day ... thank you !!!

  • @Fiedroz
    @Fiedroz 4 года назад +1

    Nice! I was using a 3d collider for 2d game, thanks for helping! :)

  • @hhhl3555
    @hhhl3555 3 года назад

    Ты легенда. Спасибо за детство

  • @itz_ak4085
    @itz_ak4085 2 года назад

    This is very helpful, I Subscribed :)

  • @Miki-gd4rq
    @Miki-gd4rq Год назад

    Very helpful and great explanation, thanks man

  • @baisk7105
    @baisk7105 4 года назад

    you literlly safed my life

  • @GustavoPLima
    @GustavoPLima 3 года назад

    you save me again! thanks from brazil

  • @makemoneyonlinewithjannie
    @makemoneyonlinewithjannie 3 года назад +2

    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.

  • @well5832
    @well5832 4 года назад

    increible Thanks CodeMonkey:D

  • @christo-j5507
    @christo-j5507 4 года назад

    Great work and you're so excellent! Helped me a lot.

  • @bananaramaman9031
    @bananaramaman9031 2 года назад

    Thank you for this video!

  • @jamaass
    @jamaass 4 года назад

    Thank you! You saved my life!

  • @pradhyumansolanki6509
    @pradhyumansolanki6509 8 месяцев назад

    broooooooooooooooooooo,thank my gooooooooooooooooood,really i mean it you are an absoulte lifesaver

  • @jmiller6224
    @jmiller6224 3 года назад

    So helpful, thank you as always!

  • @madbitscience6230
    @madbitscience6230 3 года назад

    Great tutorial! Thank you so much!

  • @DonHart
    @DonHart 3 года назад

    Saved me... my hero!

  • @stepaburianek8994
    @stepaburianek8994 3 года назад

    I WAS SEARCHING FOR THIS FOR HOURS YOU SAVED MY COMPUTER FROM ME XDD

  • @mynameisDuck
    @mynameisDuck 4 года назад

    Dude I had everything right except I was using OnTriggerEnter instead of OnTriggerEnter2D! Thanks!

  • @sabeelm9
    @sabeelm9 11 месяцев назад

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  11 месяцев назад

      Yup I've made that mistake myself several times when I was a beginner

  • @James-zp5ly
    @James-zp5ly 3 года назад +1

    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

  • @Steve-gi2yj
    @Steve-gi2yj 3 года назад

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      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)

  • @cate01a
    @cate01a 2 года назад

    cheers! my issue was using OnTriggerEnter instead of OnTriggerEnter2D :)

  • @omidnajmi6019
    @omidnajmi6019 Год назад

    thank u man, u solved my problem

  • @GameDevCaptainBlack
    @GameDevCaptainBlack Год назад

    Thank you King

  • @kodiboy18
    @kodiboy18 4 года назад

    I LOVE YOU !!! THANK YOU

  • @NguyenHoangPhuong-qf6xb
    @NguyenHoangPhuong-qf6xb 3 года назад

    you save my life!

  • @RC-hi5sj
    @RC-hi5sj 4 года назад

    Very informative thanks

  • @UltraSuprDuprVikiman
    @UltraSuprDuprVikiman 4 года назад

    Man, i f****** love you

  • @xXC0rn3rXx
    @xXC0rn3rXx 4 года назад +2

    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)

  • @oink55
    @oink55 3 года назад +1

    Thanks! ;)

  • @lamakinasamba
    @lamakinasamba 2 года назад

    Thanks, very useful

  • @sonashubhamvats6317
    @sonashubhamvats6317 4 года назад

    Bro u r the best

  • @k_dash99
    @k_dash99 4 года назад +2

    Great video, thanks . I wasnt getting any output from the OnTriggerExit function due to I was testing collision vs collsion2d

  • @freedie2592
    @freedie2592 2 года назад

    THANK YOU!

  • @stakes_z
    @stakes_z 2 года назад +1

    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
      @CodeMonkeyUnity  2 года назад +1

      You can use Physics.OverlapSphere(); or Physics2D.OverlapCircle();
      It will find all objects will colliders within range

    • @stakes_z
      @stakes_z 2 года назад

      @@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?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      ​@@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 ruclips.net/video/0jTPKz3ga4w/видео.html
      Or use Physics.OverlapSphere if you want to test with a bit of range

    • @stakes_z
      @stakes_z 2 года назад

      @@CodeMonkeyUnity Awesome! Thank you so much! I'll create my globe with multiple meshes and try it. Thank you

    • @stakes_z
      @stakes_z 2 года назад

      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

  • @luke4djojo
    @luke4djojo 4 года назад

    3:08 - legend says this is the moment a young naive man somewhere west in brazil raged with the intensity of a thousand Suns.

  • @clarissearaujo1800
    @clarissearaujo1800 4 года назад

    Thanks dude!!! you save me :D

  • @Wisdom-threads1
    @Wisdom-threads1 4 года назад

    Thanks bro you saved me

  • @tweedieproductions2637
    @tweedieproductions2637 4 года назад +1

    Thanks

  • @collosalcake236
    @collosalcake236 2 года назад

    your typing speed is faster than light omg

  • @monitor1045
    @monitor1045 4 года назад

    God bless you!!

  • @bruh-moment-21
    @bruh-moment-21 4 года назад

    Awesome!

  • @zekiel3942
    @zekiel3942 2 года назад

    Nice thank you :)

  • @wolfenergy4219
    @wolfenergy4219 4 года назад

    OMG thanks for this video my only problem was the little "2D" you need to add after OnTriggerEnter and the collider

    • @GumbazCulumbaz
      @GumbazCulumbaz 3 года назад

      Same here

    • @yatogami2159
      @yatogami2159 2 года назад

      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

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  5 лет назад +1

    Confused about collisions? This video will help!
    🎮 Play 7 Awesome Games (Action, Strategy, Management) and Help Support the Channel!
    ✅ Get the Game Bundle 67% off unitycodemonkey.com/gameBundle.php

  • @sanskarkhunt
    @sanskarkhunt 4 года назад

    Thanks code monkey for helping us..