Комментарии:
I've only just recently began my game development journey after 20 years in a technical space concerning metrology. I find your videos to be down to Earth and easy to grasp. I love the simplicity here with centralizing the processing of collisions. Good work. Can't wait for Blood & Mead!
ОтветитьI don't understand why you would need to write them twice. Most objects are either trigger or not trigger. Not trigger colliders will never call the OnCollisionEnter function. I guess it could be useful for an arcade type game where you don't necessarily want to put scripts on every spike object.
ОтветитьThe reason you don't see such code used much is because you have a very specific use-case where collision and trigger do the same thing.
It's neat code, but not scalable. Do not do this.
What if a platform (trigger area) heals the player or gives some temporary buff/debuff?
You need to add that logic into player as well... that can get very messy very quickly.
That's why I usually see people place the logic in the object initiating the action, and not the entity being affected by it.
Spikes will damage entities that collide with them, instead of entities having to handle damage when touching spikes.
And instead of using tags, use interfaces to detect something that can be damaged, i.e: collision.GetComponent<IDamagable>() or something like that.
im so shit at codig i cant make this work, the chacater collides and nothing happens why the heck did i chose to study this im screwed
ОтветитьReally nice video.
Ответитьwhat is gameObject reffering to? i assume to the object that has this script as a component, aka the player in this case.
ОтветитьIf you do this, and your collider is on a subobject, the OnCollisionEnter2D() will get the gameobject from the parent. The OnTriggerEnter2D() will get the gameobject that the collider is attached too.
To fix this do OnTriggerEnter2D() => ProcessCollision(collision.gameObject) and OnCollisionEnter2D() => ProcessCollision(collision.collider.gameObject)
The next step would be to move the collision detection to its own script and use events, that way you separate the logic from the callback making it even cleaner :)
Ответить❤
Ответитьsir you r awsome
ОтветитьAwesome Video. Thanks for the help.
ОтветитьTHIS IS PERFECTT I didnt know trigger so i didnt know what to doasjlk;dfajsl;dfsafdsa TYYY
ОтветитьWow, making a function for code that occurs in multiple places... Who would have thought of that...
Seriously when you put beginner and unity in the same title I think that as a unity beginner I am going to learn something.
Stop making Unity tutorial that are actually coding tutorial, I am watching Unity tutorial to learn about the game engine not basic programming stuff. There is nothing wrong about making coding tutorial, but phrasing it as if you were going to teach us anything about collisions in Unity is wrong.
You deserve a prize for this, that's some sharp headspace saving simplification, well done man
Ответитьglad to see that zlatan is exploring his talent in game development aswell. He was pretty good playing football
Ответитьthank you it is arbic
ОтветитьÓMG thank you! :DDDD
ОтветитьThank you very muchhh!! This totally solve my questions!
ОтветитьTy jsi Čech že? :D
ОтветитьVery interesting concept. This centralizing systems could help a lot in every situation in coding since almost every project needs a serie of collisions methods. Thanks it was a nice video!
ОтветитьGreat tip! I saved it on my notes :)
Ответитьthx for help
ОтветитьVery helpful and awesome
ОтветитьNice tip - thank you
ОтветитьMaybe you haven't found it on another collision tutorial because what you are doing is related to a software design principle called DRY (Don't Repeat Yourself) combined with the refactoring method called "Extract Method".
ОтветитьNot really "a better way to manage collisions" but like basics of code structuring and programming. "no code duplication" is like one of the most basic rules to programming.
"Yeah, few different things do the same action, let's wrap this action into a function and let each thing call the function" :D
i misheard "in this video i wanna shave with you" XD
p.s. Thank you for tutorial o/
Thank you for sharing your knowledge !
ОтветитьThats one loud keyboard
ОтветитьDo you have a video for this where it shows your health bar going down when you get damage? I got your tutorial here to work for me to see the get hit debug code but now im trying to incorporate this code with my health bar code that i currently have set to go down every time i hit my F key. i want that to be for when the enemy collides with my character but i keep getting a weird error
ОтветитьAmazing! Does this technique work for colliders only or I can use it in other parts of the code?
Ответитьso john wick is a game dev now huh?
Ответитьhow come your player isnt falling through the floor after triggerign the red spikes? in my project whenever i enter my portal collider (which transfers me to the next scene) no matter how i set the portal trigger i always fall of the ground if i didnt add an extra invisible box collider2D in my ground object with its own box collider2D
btw my portal trigger object is more bigger than my player object if that helps
Omg , 😲 knowledge acquired, wrote twice the code. Now i know thanks :)
ОтветитьThank You Very Much You Video Helped Me A Lot
ОтветитьHello I’m working on a 2D platformer I ah e a box collider on a moving sprite that’s lava but I want to register more than one collision how do I do this please PM me thanks
ОтветитьDo you have any idea to set a cooldown for collision damage? my player dies toooo fast when he collides with an enemy after collision checks
ОтветитьI don't know man but you look like Jesus.
ОтветитьThis kind of enters in the "Single-responsibility principle" pattern.
ОтветитьIf OnTriggerEnter and OnCollisionEnter have the same function, as showed in this video, why do you have to write both of them in 1 c# script?
Can you tell me the difference between them?
Isnt this just... making a function?
ОтветитьThank you! I was having SO much trouble on how to check what collision is being detected, and I couldn't find anything to help me until I found this!
ОтветитьThe difference between trigger and no-trigger : thank you for the tip - while it is so obvious, I missed the point so far...
ОтветитьI need to set a game object after colliding with a trigger, like a puck to a face off circle after colliding with a goal trigger and different face off circles after colliding with boundary triggers
Ответитьthank you brother ...
ОтветитьEven better, use Actions/Events
Ответитьthis is pretty straightforward, but for some reason I also have not implemented it! thanks for the tip!
ОтветитьI'll use this. thanks man
ОтветитьHello...
Pl help as soon as possible.
Tried a 2D game,
Find the difference game.
Touching d screen on d object it triggered and result correct, and if touched background image it triggers and results wrong.
Placed d pointer down.
If we touched the object, since the pointer moving towards we touched, it automatically triggers the bg first and then the object.
Results - first msg as wrong, immediately correct.
How to overcome this. Since bg image is 2dboxcollider even if we increase z axis, it collides .
Can we directly switch(jump) to the touched point without passing through the bg image area.