Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Rubikpotato · Jan 09, 2015 at 07:11 PM · 2d-platformer2d-physics2d-sidescroller

2d Sidescroll problem with wall sliding

So I'm currently making a 2d sidescroll and I found a problem, my character remained "stuck" with a vertical wall when I jumped to it and was not sliding down to the floor. I looked up on the internet and "fixed" it by using physics 2d material and now the character slid, but now as the material affects the whole collider, the character slides in the whole platform, not only in the sides. So I used two box colliders, one for the upper part of the platform, and other that occupies the rest of the platform, but that ended with my character getting stuck in the corner of the platforms (I did the same but with the character). So my question is: There is way to affect only some sides of a collider (box collider 2d) with a physics material? Or there is a way to fix my problem by code, such as "behaviorWithWalls"?

Don't know if relevant but I'm using rigidbody2d.velocity to move my character and making it jump.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SnStarr · Jan 10, 2015 at 06:37 AM

If you're using raycast functions for your player to detect collisions within 2d space, like raycasting above and below him to detect colliders then the common problem would be that you need to also have raycast not only check above and below the player for collisions, but also left and right. If its because he is getting stuck on "corners" or objects with box colliders have the raycast check at an angle in the direction he's moving. Like after you jump while moving forward and hes falling, the raycast needs to check the combination of his forward vector and his downward vector. You can do this by usind a For Loop with a Lerp amount on a Vector 3. Or else he will get stuck on box collider corners. If I read your op wrong, im sry try this tutorial

use this tutorial. http://deranged-hermit.blogspot.com/2014/01/2d-platformer-collision-detection-with.html

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rubikpotato · Jan 10, 2015 at 03:24 PM 0
Share

TY, and how do I do with cliffs? so when the player is trying to walk in a cliff he doesn't just slide... Also, I can do the same you explained but with linecast? because I think I don't understand that much about raycast...

avatar image SnStarr · Jan 10, 2015 at 03:57 PM 0
Share

Yes I meant LineCast...I always just say raycast but forget to call it line casting when talking about 2D. Line casts should be cast in 10 directions to detect collisions at all times on a 2D surface. Similar to something like this. Although I think 3 lines cast from bottom like, 1 on each edge and 1 in the center. And three at the top. One on each side and then one in each corner. Can be done in a single function im pretty sure. Sorry, I am more designer than coder, and I am sure a coder will come along and tell me im wrong or right.alt text

untitled.png (3.4 kB)
avatar image SnStarr · Jan 10, 2015 at 04:01 PM 0
Share

Now that I think about it, You could prolly use one LineCast and just have it cast in the velocity the play is moving. $$anonymous$$eaning if he is falling & moving right, then the line cast would cast from the bottom right corner. If he was jumping and walking left it would cast from the top left and well, you get the picture. Literally above.

avatar image Rubikpotato · Jan 10, 2015 at 04:45 PM 0
Share

Yeah I get it, but what I'm supposed to do with the information when the player detect nearby walls, I mean how the player have to "react" to prevent stucking with walls? The only thing I have on $$anonymous$$d (because of my very basic knowledge) is to stop the player by a Vector2.zero (on the rigidbody.velocity), but that would just freeze the player until he reachs the floor.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

The name `CrossPlatformInput' does not exist in the current context 3 Answers

The name `PlatformerCharacter2D' does not exist in the current context 1 Answer

How do I get the character to jump in a 2d game, which is compatible with joysticks and keyboards? 0 Answers

2D moving platforms, physics issues 1 Answer

2D Character won't jump diagonally 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges