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...
Im the 1,000 sub!
Haha, I love you! Thank you!
this is better than any one-way platform tutorial for unity I've seen so far!! good job!!
I really like how simple your tutorial usually are. Definitely helpful for my final project
Cant get over how your videos are so quick and concise but still so informative and clever! Big up yourself !
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.
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!
been trying to make a one way jump for weeks and finally found the best video for it
Saving this for the future! Definitely gonna need it
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!
Easier than I thought
Thanks man
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.
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?
This is great, I'm very new to development as well, thank you for showing all the script and what to click on Unity.
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
thank you for the straight to the point videos.
I like your tutorials!
Keep it up!
Nice tutorial! Helpful technique described with elegant simplicity. Fun design!
SUBSCRIBED! I REALLY NEED THISSSSS..
Please keep making 2D unity tutorials!
This video was exactly what I was looking for! Subbed! Great work!
Great work ! Thanks !!
I'm a beginner too. So as long as it works. There is no better way. Lol. Thanks a bunch!!
you are the best in tutorials it always work thanks
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...?
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!
I'm glad you were able to fix it.
@@Toon444 thanks, I was changing it to a higher number, its lower, helped me a lot
Amazing tutorial, thank you!
Thank you so much man great tutorial!
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!
its a NullReferenceException, the thing works fine its just I don't know if i should worry or not
It's hard to tell what's going on without seeing your script.
Great tutorial! 🎉
thank you :)
I am trying to bind the left trigger down but its not working
Brooo thankssss
Thank you!!
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?
It's hard to tell what's going on without seeing your script.
Make more vedios pls 😀
thanks
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.
Edit > Preferences > External Tools > External Script Editor
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?
Decrease the surface arc of your platform's Platform Effector 2D component.
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.
Decrease the surface arc of your platform's Platform Effector 2D component.
@@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)
@@veijiouuuu Have you referenced your player's Box Collider 2D component in Unity?
@@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)
I know its a while after the video upload but how do i make the platform frictionless?
Create a Physics Material 2D, set the friction to zero, and add it to your player's Rigidbody 2D component.
@@bendux ok tysm
how do you move your mouse so smooth?
I use a software called AutoHotkey.
how to make the background in this video bro
I would recommend checking out Unity's particle system.
Could you attach the source code? I keep getting some odd errors and I want to compare my code to yours.
I've added a link to the source code to the description.
I didn’t know about Physics2D.IgnoreCollision() 👀
I made one way platforms recently. It seems every time you upload I have to rewrite something 😂
Hahaha, I'm sorry, neenaw!
I added a PlatformEffector2D script to my platform and despite its settings being correct, my player can't go through it. Can anyone help?
Make sure that Used By Effector is checked in the Box Collider 2D component.
I did. Still doesn't work@@bendux
@@Tidalley Join our Discord server, and let's solve your problem together!
You still collide with the sides of the platform. Know how to fix this?
Decrease the surface arc of your platform's Platform Effector 2D component.
@@bendux Maybe pin this comment, so it's easier to find? I had the exact same idea.
@@bendux epic :)
ur awesome
Despite the fact that I am from Ukraine and do not understand English very well, it is just fascinating.
can you make tutorial for your background plzzz
I definitely want to make a video about Unity's particle system in the future.
@@bendux ok nice
This tutorial was helpful but for some reason my character can't jump off of the platform.
nvm i got help in the discord i forgot to change the layer to ground
I'm glad you were able to fix it.
❤❤❤❤❤❤❤❤❤❤
skibidi toilet
Thank you!