How To Make 2D One-Way Platforms In Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024
  • Learn how to make 2D one-way platforms in Unity!
    Source code: gist.github.co...
    SOCIAL
    Discord: / discord
    itch.io: bendux.itch.io/
    Twitter: / bendux_studios
    SUPPORT
    Buy Me a Coffee: www.buymeacoff...
    MUSIC
    Backbay Lounge by Kevin MacLeod
    Link: incompetech.fi...
    License: filmmusic.io/s...

ความคิดเห็น • 81

  • @asasin8129
    @asasin8129 2 ปีที่แล้ว +17

    Im the 1,000 sub!

    • @bendux
      @bendux  2 ปีที่แล้ว +3

      Haha, I love you! Thank you!

  • @brunolam50
    @brunolam50 3 ปีที่แล้ว +10

    this is better than any one-way platform tutorial for unity I've seen so far!! good job!!

  • @Lowshortx
    @Lowshortx 2 ปีที่แล้ว +4

    I really like how simple your tutorial usually are. Definitely helpful for my final project

  • @monarchdrumandbass8700
    @monarchdrumandbass8700 ปีที่แล้ว +4

    Cant get over how your videos are so quick and concise but still so informative and clever! Big up yourself !

  • @goldencookie5456
    @goldencookie5456 8 หลายเดือนก่อน +1

    I'm specifically trying to make one way platforms with tiles.
    There are many issues I've come across.
    Firstly, enabling one way platforms for me, is not good enough since you aren't able to go through the platform from the side. It simply acts as a wall if you approach from the side even if your y position is below the platform's y position. I personally can't accept that for my game.
    So I decided I will have to script it.
    Chatgpt and some youtuber suggested I simply check for the player's position relative to the tiles in the platform, and check and uncheck the collider of the tilemap collider when above or below. But this too has issues. If I have two 1 way platforms placed directly vertically adjacent to each other, and my player is tall enough to be touching both, there is the issue of my player being both above and below certain tiles in the tilemap. Since you can't directly enable and disable specific parts of a tilemap collider, and can only affect the whole thing, I can only enable or disable the whole tilemap's collider, meaning I will either be stuck between 2 platforms, or fall through both.
    One possible solution I thought of, was if instead of using a tilemap collider, I dynamically instantiated and destroyed box colliders (or moved by using object pooling to improve performance) onto the position of the tiles.
    There will be a tile check around the player in a 3x2 tile radius. And if tiles are found, it'll check for if the player is above or below it. If above, the collider will appear.
    For other objects or enemies that are meant to be on said platforms, I can have a tilemap layer that doesn't interact with the player layer so they don't fall through.
    Honestly though, I have 0 clue as to what I'm doing. I'm a total beginner, so I apologize if this sounds stupid and impractical. I'm in the middle of making my first game.
    Edit: OMG I just found out what the arc thing was for. Nvm this whole comment.
    2nd Edit: Nvm again, still have the same problem.
    3rd Edit: Nvm again, just needed to adjust some components. Now it works completely without any issues.
    Here is a summary of what happened throughout each edit:
    Initially, I had:
    -composite collider enabled
    -platformer effector 2d enabled
    -Use one way on
    -Use one way grouping on
    -Surface arc 180
    ~The result was that I could not go through the platform from the side. That's when I tried coming up with a solution through scripting and wrote this comment. But I found out about surface arc soon enough.
    So I changed it to:
    -composite collider enabled
    -platformer effector 2d enabled
    -Use one way on
    -Use one way grouping on
    -Surface arc 90*
    ~Changing the surface arc allowed me to go through the side. But I had the 2nd issue I mentioned in my comment where if my player was touching 2 vertically adjacent platforms, it would fall through both despite being above the bottom platform.*
    And then:
    -composite collider enabled
    -platformer effector 2d enabled
    -Use one way on
    -Use one way grouping off*
    -Surface arc 90
    ~Turning one way grouping off had it's own issue where I could jump on the bottom of the tile collider where my player would be able to go inside the tile.*
    And then finally:
    -composite collider disabled*
    -platformer effector 2d enabled
    -Use one way on
    -Use one way grouping off
    -Surface arc 90
    ~Finally, I tried disabling the composite collider to see what it'd too. And surprisingly, it began working perfectly. Just found by pure experimentation.
    Now it works exactly as it should. As functional as terraria platforms for example.
    Hopefully I won't have to make another edit onto this comment.
    Edit:
    Welp that didn't last long.
    But not to worry, it still works completely fine, but I simply came across another separate issue to do with my groundcheck. My groundcheck checks if my player is grounded through a boxcast just below the player. While jumping through the 1 way platform, due to my boxcast returning true, I am able to jump again midair, since the groundcheck is checked. I will try to come up with a solution.

  • @oswaldodavidgarciarodrigue2301
    @oswaldodavidgarciarodrigue2301 ปีที่แล้ว +1

    Ultra like! I'm creating a endless runner game and this is the perfect tutorial I needed to deal with one way platforms. Thank you so much!

  • @mustafaal-muthaffar8639
    @mustafaal-muthaffar8639 ปีที่แล้ว

    been trying to make a one way jump for weeks and finally found the best video for it

  • @DevNoob
    @DevNoob 3 ปีที่แล้ว +1

    Saving this for the future! Definitely gonna need it

  • @greglhoffmann
    @greglhoffmann ปีที่แล้ว

    Much easier to have the code attached to the player than to the platform in case you have multiple players interacting with platforms at once. Thanks!

  •  6 หลายเดือนก่อน

    Easier than I thought
    Thanks man

  • @Spellbook
    @Spellbook 3 ปีที่แล้ว

    nice nice nice, 3 mins tutorial and so much info. Thank you
    some long video tutorials in youtube are great because they explain things but sometimes i'd rather read the documentation later.

  • @danielrdrigues
    @danielrdrigues หลายเดือนก่อน

    If the player takes longer to pass through, isn't the collider going to come back and make the player stuck? wouldn't be better a redundancy to check if the player still inside the collider?

  • @Cjoudan
    @Cjoudan 2 ปีที่แล้ว

    This is great, I'm very new to development as well, thank you for showing all the script and what to click on Unity.

  • @Marble-Animations
    @Marble-Animations หลายเดือนก่อน

    Hey there, thanks for this video man, I did not know Unity added those platform components.
    Do you mind i see the player script. I wanna see how you made it as I'm having bugs with my own player script

  • @castillo10021
    @castillo10021 ปีที่แล้ว

    thank you for the straight to the point videos.

  • @johnrasc6544
    @johnrasc6544 3 ปีที่แล้ว +2

    I like your tutorials!
    Keep it up!

  • @woodenfences
    @woodenfences 3 ปีที่แล้ว

    Nice tutorial! Helpful technique described with elegant simplicity. Fun design!

  • @alviratulaha8618
    @alviratulaha8618 3 ปีที่แล้ว

    SUBSCRIBED! I REALLY NEED THISSSSS..
    Please keep making 2D unity tutorials!

  • @willwilson4486
    @willwilson4486 3 ปีที่แล้ว

    This video was exactly what I was looking for! Subbed! Great work!

  • @kalvindelcenserie3719
    @kalvindelcenserie3719 2 ปีที่แล้ว +1

    Great work ! Thanks !!

  • @It-is-PhillipFrank
    @It-is-PhillipFrank 8 หลายเดือนก่อน

    I'm a beginner too. So as long as it works. There is no better way. Lol. Thanks a bunch!!

  • @Ai-nv6zs
    @Ai-nv6zs ปีที่แล้ว

    you are the best in tutorials it always work thanks

  • @Toon444
    @Toon444 2 ปีที่แล้ว +2

    Incredible tutorial! Normally I get a million error messages when following other tutorials but yours had 0 problems! Also, I was wondering if there was a way to make it so that the player also doesn't collide with the side of the platform...?

    • @Toon444
      @Toon444 2 ปีที่แล้ว +1

      Nevermind! I saw the answer in another comment. You just have to decrease the surface arc (I set it to 50) of the Platform Effector 2D component!

    • @bendux
      @bendux  2 ปีที่แล้ว

      I'm glad you were able to fix it.

    • @lucasbgabriel1441
      @lucasbgabriel1441 ปีที่แล้ว

      @@Toon444 thanks, I was changing it to a higher number, its lower, helped me a lot

  • @nickolasmachado9274
    @nickolasmachado9274 3 ปีที่แล้ว

    Amazing tutorial, thank you!

  • @asasin8129
    @asasin8129 2 ปีที่แล้ว

    Thank you so much man great tutorial!

  • @suryakrishnan3457
    @suryakrishnan3457 5 หลายเดือนก่อน +1

    Hi, anytime i click the down arrow anywhere except for on top of the platform I get an error, should I be worried or not? Thanks and great tutorial otherwise!

    • @suryakrishnan3457
      @suryakrishnan3457 5 หลายเดือนก่อน

      its a NullReferenceException, the thing works fine its just I don't know if i should worry or not

    • @bendux
      @bendux  3 หลายเดือนก่อน

      It's hard to tell what's going on without seeing your script.

  • @MrEggplantation
    @MrEggplantation 2 ปีที่แล้ว

    Great tutorial! 🎉

  • @hadriel.
    @hadriel. 2 ปีที่แล้ว +1

    thank you :)

  • @noobdev6464
    @noobdev6464 8 หลายเดือนก่อน

    I am trying to bind the left trigger down but its not working

  • @Slakskskssksksks
    @Slakskskssksksks 6 หลายเดือนก่อน

    Brooo thankssss

  • @mediamermaid333
    @mediamermaid333 9 หลายเดือนก่อน

    Thank you!!

  • @jeffersonmarvel5189
    @jeffersonmarvel5189 3 หลายเดือนก่อน

    My Character was fall down, i dont know what happened while I'm following this code, my char fall down, before use this code the char doesn't fall down, any solution?

    • @bendux
      @bendux  3 หลายเดือนก่อน

      It's hard to tell what's going on without seeing your script.

  • @minasami7729
    @minasami7729 3 ปีที่แล้ว +2

    Make more vedios pls 😀

  • @neconunyerigeldi-dv6xr
    @neconunyerigeldi-dv6xr ปีที่แล้ว

    thanks

  • @afro_corndawg
    @afro_corndawg 2 ปีที่แล้ว

    How come when I code the words don't turn the same colors as most tutorials? Is it a setting I need to turn on? The code still works the same but it looks easier to read and follow along with other Unity tutorials.

    • @bendux
      @bendux  2 ปีที่แล้ว +2

      Edit > Preferences > External Tools > External Script Editor

  • @kbg12ila
    @kbg12ila 2 ปีที่แล้ว

    Hi. Do you know how I can make it so the one way collision platforms only land when my players feet collide with the top side of the platform. Just using the effector allows me to jump through the bottom but when jumping from the side my players body collides with the platform. For example if the platform was up to my players knees I would want my player to be able to walk through the platform but if my played jumped he would land on the top side of the platform. Any idea how to do this?

    • @bendux
      @bendux  2 ปีที่แล้ว +1

      Decrease the surface arc of your platform's Platform Effector 2D component.

  • @veijiouuuu
    @veijiouuuu ปีที่แล้ว

    Suscribed!! thanks bendux! One question...
    How can I make my character walk onto a platform without hitting the collider?
    Because when the platform is at the same height as the character, it doesn't let him move forward.
    I would like the platform let my character pass through it without hitting the collider but to retain the One-Way properties.

    • @bendux
      @bendux  ปีที่แล้ว +1

      Decrease the surface arc of your platform's Platform Effector 2D component.

    • @veijiouuuu
      @veijiouuuu ปีที่แล้ว

      @@bendux Saw the answer down below! thanks anyway mate!!! But for some reason, when I press key down, my character wont come down :(
      Error:
      ArgumentNullException: Value cannot be null.
      Parameter name: collider2
      UnityEngine.Physics2D.IgnoreCollision (UnityEngine.Collider2D collider1, UnityEngine.Collider2D collider2) (at :0)
      PlayerOneWayPlatform+d__5.MoveNext () (at Assets/Scripts/PlayerOneWayPlatform.cs:44)
      UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0)
      UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
      PlayerOneWayPlatform:Update() (at Assets/Scripts/PlayerOneWayPlatform.cs:19)

    • @bendux
      @bendux  ปีที่แล้ว

      @@veijiouuuu Have you referenced your player's Box Collider 2D component in Unity?

    • @veijiouuuu
      @veijiouuuu ปีที่แล้ว

      @@bendux I found out what was wrong, the box collider of the platform was to thick (i think...) so in the code line yield return new WaitForSeconds(0.4f), instead of 0.25f)

  • @Cameron_Maguire
    @Cameron_Maguire ปีที่แล้ว

    I know its a while after the video upload but how do i make the platform frictionless?

    • @bendux
      @bendux  ปีที่แล้ว

      Create a Physics Material 2D, set the friction to zero, and add it to your player's Rigidbody 2D component.

    • @Cameron_Maguire
      @Cameron_Maguire ปีที่แล้ว

      @@bendux ok tysm

  • @frankiepinat1644
    @frankiepinat1644 ปีที่แล้ว

    how do you move your mouse so smooth?

    • @bendux
      @bendux  ปีที่แล้ว

      I use a software called AutoHotkey.

  • @IKairo1208
    @IKairo1208 ปีที่แล้ว

    how to make the background in this video bro

    • @bendux
      @bendux  ปีที่แล้ว

      I would recommend checking out Unity's particle system.

  • @mr.pyckle3882
    @mr.pyckle3882 ปีที่แล้ว

    Could you attach the source code? I keep getting some odd errors and I want to compare my code to yours.

    • @bendux
      @bendux  ปีที่แล้ว

      I've added a link to the source code to the description.

  • @neenaw
    @neenaw 3 ปีที่แล้ว

    I didn’t know about Physics2D.IgnoreCollision() 👀
    I made one way platforms recently. It seems every time you upload I have to rewrite something 😂

    • @bendux
      @bendux  3 ปีที่แล้ว

      Hahaha, I'm sorry, neenaw!

  • @Tidalley
    @Tidalley ปีที่แล้ว

    I added a PlatformEffector2D script to my platform and despite its settings being correct, my player can't go through it. Can anyone help?

    • @bendux
      @bendux  11 หลายเดือนก่อน

      Make sure that Used By Effector is checked in the Box Collider 2D component.

    • @Tidalley
      @Tidalley 11 หลายเดือนก่อน

      I did. Still doesn't work@@bendux

    • @bendux
      @bendux  11 หลายเดือนก่อน

      @@Tidalley Join our Discord server, and let's solve your problem together!

  • @ZachToons888
    @ZachToons888 2 ปีที่แล้ว

    You still collide with the sides of the platform. Know how to fix this?

    • @bendux
      @bendux  2 ปีที่แล้ว

      Decrease the surface arc of your platform's Platform Effector 2D component.

    • @pyxelgamer
      @pyxelgamer 2 ปีที่แล้ว

      @@bendux Maybe pin this comment, so it's easier to find? I had the exact same idea.

    • @moonwatchereclipse5291
      @moonwatchereclipse5291 ปีที่แล้ว

      @@bendux epic :)
      ur awesome

  • @seesonrise
    @seesonrise ปีที่แล้ว

    Despite the fact that I am from Ukraine and do not understand English very well, it is just fascinating.

  • @crane4324
    @crane4324 2 ปีที่แล้ว

    can you make tutorial for your background plzzz

    • @bendux
      @bendux  2 ปีที่แล้ว

      I definitely want to make a video about Unity's particle system in the future.

    • @crane4324
      @crane4324 2 ปีที่แล้ว

      @@bendux ok nice

  • @applesaurusrex8075
    @applesaurusrex8075 ปีที่แล้ว

    This tutorial was helpful but for some reason my character can't jump off of the platform.

    • @applesaurusrex8075
      @applesaurusrex8075 ปีที่แล้ว

      nvm i got help in the discord i forgot to change the layer to ground

    • @bendux
      @bendux  ปีที่แล้ว

      I'm glad you were able to fix it.

  • @joaovitorfonseca5106
    @joaovitorfonseca5106 3 ปีที่แล้ว

    ❤❤❤❤❤❤❤❤❤❤

  • @scripted5522
    @scripted5522 9 หลายเดือนก่อน +1

    skibidi toilet

  • @TopRapter
    @TopRapter 3 ปีที่แล้ว

    Thank you!