Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 MadBorisGames · Sep 10, 2018 at 03:00 PM · 2d-physicsslopes

[2D] How to stop my character on slopes?

I've got issue with slopes and chaarcter. When I'm going in a high slope, my character goes up (exactly this) and I don't want it. When program prints "On high slope" I want to make fall character down and be unable to walk on slopes, but I don't know how to do this. Maybe I'm approaching it wrong. Thanks in advance.

 //I just have high slope detection
 //I put it in FixedUpdate()
 private void Slope() {
         RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up, 3f, whatIsGround);
         if (hit.collider != null) {
             if (Mathf.Abs(hit.normal.x) > maxSlope) {
                 print("On high slope");
             }
         }
     }


Comment
Add comment · Show 1
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 misher · Sep 10, 2018 at 03:06 PM 1
Share

It depends on how you have implemented character movement

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by RaphaelQuem · Sep 10, 2018 at 04:23 PM

Are you using a RigidBody or only a BoxCollider? And what code are u using to move it around?

Comment
Add comment · Show 3 · 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 MadBorisGames · Sep 10, 2018 at 04:36 PM 0
Share

I'm using Rigidbody2D with BoxCollider2D and this is my entire movement code https://pastebin.com/mw$$anonymous$$mijak

avatar image RaphaelQuem MadBorisGames · Sep 10, 2018 at 04:45 PM 0
Share

Okay!

So, i'm not with my unity available right now, but if i understood your code right, if you add "if($$anonymous$$athf.Abs(hit.normal.x) <= maxSlope)" wrapping the line 71 and 72, it'll do.

It won't add any force to the rigidbody programatically and the unity gravity will take care of the body sliding down the slope.

If the player continues to push forward, it will remain in the max slope, since when it reaches the top it slides back a little.

avatar image MadBorisGames RaphaelQuem · Sep 10, 2018 at 05:05 PM 0
Share

Okay, That works fine! I have some little issues with this solution (e.g. I can't move in the direction opposite to the slope), but I think I can solve that problem :D. Thank you so much <3

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

92 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to keep a 2D platformer character grounded when traversing slopes. 0 Answers

Is it possible to swap my x Axis and y Axis on a rigidbody2D? 1 Answer

Change Speed of Multiple Objects of the same Class 2 Answers

Physics makes 2D object rotate around its pivot 1 Answer

My object is rotating crazily - 2D 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